"""Remove item.receiptitem relationship

Revision ID: cdbe3f5e3b30
Revises: 0fa2ef37e440
Create Date: 2023-09-19 19:02:23.003034

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'cdbe3f5e3b30'
down_revision = '0fa2ef37e440'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('receipt', schema=None) as batch_op:
        batch_op.alter_column('id',
               existing_type=sa.INTEGER(),
               type_=sa.BigInteger(),
               existing_nullable=False,
               autoincrement=True)

    with op.batch_alter_table('receipt_item', schema=None) as batch_op:
        batch_op.add_column(sa.Column('price', sa.SmallInteger(), nullable=False))
        batch_op.alter_column('receipt',
               existing_type=sa.INTEGER(),
               type_=sa.BigInteger(),
               existing_nullable=False)
        batch_op.alter_column('item',
               existing_type=sa.BIGINT(),
               type_=sa.SmallInteger(),
               existing_nullable=False)
        batch_op.drop_constraint('item_receipt_item_fkey', type_='foreignkey')

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('receipt_item', schema=None) as batch_op:
        batch_op.create_foreign_key('item_receipt_item_fkey', 'item', ['item'], ['id'])
        batch_op.alter_column('item',
               existing_type=sa.SmallInteger(),
               type_=sa.BIGINT(),
               existing_nullable=False)
        batch_op.alter_column('receipt',
               existing_type=sa.BigInteger(),
               type_=sa.INTEGER(),
               existing_nullable=False)
        batch_op.drop_column('price')

    with op.batch_alter_table('receipt', schema=None) as batch_op:
        batch_op.alter_column('id',
               existing_type=sa.BigInteger(),
               type_=sa.INTEGER(),
               existing_nullable=False,
               autoincrement=True)

    # ### end Alembic commands ###
