"""
Alembic migration: Create user_card_imports table.

This migration adds the user_card_imports table which stores
a user's imported card collection as a JSON array of card names.
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '004'
down_revision = '003'
branch_labels = None
depends_on = None


def upgrade() -> None:
    """Create user_card_imports table."""
    op.create_table(
        'user_card_imports',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('card_names_json', sa.Text(), nullable=False),
        sa.Column('created_at', sa.DateTime(), server_default=sa.func.now()),
        sa.Column('updated_at', sa.DateTime(), server_default=sa.func.now(), onupdate=sa.func.now()),
        sa.PrimaryKeyConstraint('id'),
        sa.ForeignKeyConstraint(['user_id'], ['mtgonline_users.id'], ondelete='CASCADE'),
        sa.UniqueConstraint('user_id', name='uq_user_card_imports_user_id'),
        sa.Index('idx_user_card_imports_user', 'user_id'),
    )


def downgrade() -> None:
    """Drop user_card_imports table."""
    op.drop_table('user_card_imports')
