"""add provider_config and system_setting tables

Revision ID: e13e987e2170
Revises: 6cb95261c2b7
Create Date: 2026-03-18 23:31:03.286442

"""

from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "e13e987e2170"
down_revision: str | Sequence[str] | None = "6cb95261c2b7"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "provider_config",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("provider", sa.String(length=32), nullable=False),
        sa.Column("key", sa.String(length=64), nullable=False),
        sa.Column("value", sa.Text(), nullable=False),
        sa.Column("is_secret", sa.Boolean(), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("provider", "key", name="uq_provider_key"),
    )
    with op.batch_alter_table("provider_config", schema=None) as batch_op:
        batch_op.create_index("ix_provider_config_provider", ["provider"], unique=False)

    op.create_table(
        "system_setting",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("key", sa.String(length=64), nullable=False),
        sa.Column("value", sa.Text(), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("key"),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("system_setting")
    with op.batch_alter_table("provider_config", schema=None) as batch_op:
        batch_op.drop_index("ix_provider_config_provider")

    op.drop_table("provider_config")
    # ### end Alembic commands ###
