"""add unsandbox API keys to shop

Revision ID: a1b2c3d4e5f6
Revises: d4c7d6a1e961
Create Date: 2026-02-17 00:00:00.000000

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'a1b2c3d4e5f6'
down_revision = 'd4c7d6a1e961'
branch_labels = None
depends_on = None


def _column_exists(table, column):
    conn = op.get_bind()
    result = conn.execute(sa.text(f"PRAGMA table_info({table})"))
    return any(row[1] == column for row in result.fetchall())


def upgrade():
    if not _column_exists("mps_shop", "unsandbox_public_key"):
        op.add_column(
            "mps_shop",
            sa.Column("unsandbox_public_key", sa.Unicode(128), nullable=True),
        )
    if not _column_exists("mps_shop", "unsandbox_secret_key"):
        op.add_column(
            "mps_shop",
            sa.Column("unsandbox_secret_key", sa.Unicode(128), nullable=True),
        )


def downgrade():
    op.drop_column("mps_shop", "unsandbox_secret_key")
    op.drop_column("mps_shop", "unsandbox_public_key")
