"""add sys configs

Revision ID: 21a3e778ef01
Revises: 6b603528dac8
Create Date: 2025-11-12 13:47:30.234600

"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = "21a3e778ef01"
down_revision = "6b603528dac8"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "sys_configs",
        sa.Column("id", mysql.BIGINT(), autoincrement=True, nullable=False),
        sa.Column(
            "config_bid",
            sa.String(length=36),
            nullable=False,
            comment="Config business identifier",
        ),
        sa.Column("key", sa.String(length=255), nullable=False, comment="Config key"),
        sa.Column("value", sa.Text(), nullable=False, comment="Config value"),
        sa.Column(
            "is_encrypted",
            sa.SmallInteger(),
            nullable=False,
            comment="Is encrypted: 0=no, 1=yes",
        ),
        sa.Column("remark", sa.Text(), nullable=False, comment="Config remark"),
        sa.Column(
            "deleted",
            sa.SmallInteger(),
            nullable=False,
            comment="Deletion flag: 0=active, 1=deleted",
        ),
        sa.Column(
            "updated_by", sa.String(length=36), nullable=False, comment="Updated by"
        ),
        sa.Column("created_at", sa.DateTime(), nullable=False, comment="Creation time"),
        sa.Column("updated_at", sa.DateTime(), nullable=False, comment="Update time"),
        sa.PrimaryKeyConstraint("id"),
        comment="System configs",
    )
    with op.batch_alter_table("sys_configs", schema=None) as batch_op:
        batch_op.create_index(
            batch_op.f("ix_sys_configs_config_bid"), ["config_bid"], unique=False
        )
        batch_op.create_index(batch_op.f("ix_sys_configs_key"), ["key"], unique=False)

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###

    with op.batch_alter_table("sys_configs", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_sys_configs_key"))
        batch_op.drop_index(batch_op.f("ix_sys_configs_config_bid"))

    op.drop_table("sys_configs")

    # ### end Alembic commands ###
