"""card_add_idm_chip_id

Revision ID: 48f4acc43a7e
Revises: 1e150d16ab6b
Create Date: 2024-06-21 23:53:34.369134

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

# revision identifiers, used by Alembic.
revision = '48f4acc43a7e'
down_revision = '1e150d16ab6b'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('aime_card', sa.Column('idm', sa.String(length=16), nullable=True))
    op.add_column('aime_card', sa.Column('chip_id', sa.BIGINT(), nullable=True))
    op.alter_column('aime_card', 'access_code',
               existing_type=mysql.VARCHAR(length=20),
               nullable=False)
    op.alter_column('aime_card', 'created_date',
               existing_type=mysql.TIMESTAMP(),
               server_default=sa.text('now()'),
               existing_nullable=True)
    op.create_unique_constraint(None, 'aime_card', ['chip_id'])
    op.create_unique_constraint(None, 'aime_card', ['idm'])
    op.create_unique_constraint(None, 'aime_card', ['access_code'])
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint("chip_id", 'aime_card', type_='unique')
    op.drop_constraint("idm", 'aime_card', type_='unique')
    op.drop_constraint("access_code", 'aime_card', type_='unique')
    op.alter_column('aime_card', 'created_date',
               existing_type=mysql.TIMESTAMP(),
               server_default=sa.text('CURRENT_TIMESTAMP'),
               existing_nullable=True)
    op.alter_column('aime_card', 'access_code',
               existing_type=mysql.VARCHAR(length=20),
               nullable=True)
    op.drop_column('aime_card', 'chip_id')
    op.drop_column('aime_card', 'idm')
    # ### end Alembic commands ###
