"""add_optins_column_to_user

Revision ID: e56d87f8994a
Revises: 1b8b740a6fa3
Create Date: 2025-04-09 15:57:46.904977

"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

from aiexec.utils import migration

# revision identifiers, used by Alembic.
revision: str = "e56d87f8994a"
down_revision: str | None = "1b8b740a6fa3"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    conn = op.get_bind()
    # ### commands auto generated by Alembic - please adjust! ###
    if not migration.column_exists(table_name="user", column_name="optins", conn=conn):
        with op.batch_alter_table("user", schema=None) as batch_op:
            batch_op.add_column(sa.Column("optins", sa.JSON(), nullable=True))
    # ### end Alembic commands ###


def downgrade() -> None:
    conn = op.get_bind()
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("user", schema=None) as batch_op:
        batch_op.drop_column("optins")
    # ### end Alembic commands ###
