"""add torrent_opt_in column to mps_product

Revision ID: 0ee5654cfe7d
Revises: 4f4d7c147437
Create Date: 2026-04-06 18:03:53.663932

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '0ee5654cfe7d'
down_revision = '4f4d7c147437'
branch_labels = None
depends_on = None


def _column_exists(table, column):
    from alembic import op as _op
    from sqlalchemy import inspect
    bind = _op.get_bind()
    insp = inspect(bind)
    return column in [c["name"] for c in insp.get_columns(table)]


def upgrade():
    if not _column_exists('mps_product', 'torrent_opt_in'):
        op.add_column(
            'mps_product',
            sa.Column('torrent_opt_in', sa.Boolean(), server_default='0', nullable=False),
        )


def downgrade():
    if _column_exists('mps_product', 'torrent_opt_in'):
        op.drop_column('mps_product', 'torrent_opt_in')
