|
| 1 | +"""Add a tags table |
| 2 | +
|
| 3 | +Revision ID: d53fe61e5521 |
| 4 | +Revises: 7a9b38559992 |
| 5 | +Create Date: 2024-05-16 00:32:19.566457 |
| 6 | +
|
| 7 | +""" |
| 8 | + |
| 9 | +# revision identifiers, used by Alembic. |
| 10 | +revision = 'd53fe61e5521' |
| 11 | +down_revision = '7a9b38559992' |
| 12 | + |
| 13 | +from alembic import op |
| 14 | +import sqlalchemy as sa |
| 15 | + |
| 16 | + |
| 17 | +def upgrade(): |
| 18 | + # ### commands auto generated by Alembic - please adjust! ### |
| 19 | + op.create_table('billtags_version', |
| 20 | + sa.Column('bill_id', sa.Integer(), autoincrement=False, nullable=False), |
| 21 | + sa.Column('tag_id', sa.Integer(), autoincrement=False, nullable=False), |
| 22 | + sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False), |
| 23 | + sa.Column('end_transaction_id', sa.BigInteger(), nullable=True), |
| 24 | + sa.Column('operation_type', sa.SmallInteger(), nullable=False), |
| 25 | + sa.PrimaryKeyConstraint('bill_id', 'tag_id', 'transaction_id') |
| 26 | + ) |
| 27 | + with op.batch_alter_table('billtags_version', schema=None) as batch_op: |
| 28 | + batch_op.create_index(batch_op.f('ix_billtags_version_end_transaction_id'), ['end_transaction_id'], unique=False) |
| 29 | + batch_op.create_index(batch_op.f('ix_billtags_version_operation_type'), ['operation_type'], unique=False) |
| 30 | + batch_op.create_index(batch_op.f('ix_billtags_version_transaction_id'), ['transaction_id'], unique=False) |
| 31 | + |
| 32 | + op.create_table('tag', |
| 33 | + sa.Column('id', sa.Integer(), nullable=False), |
| 34 | + sa.Column('project_id', sa.String(length=64), nullable=True), |
| 35 | + sa.Column('name', sa.UnicodeText(), nullable=True), |
| 36 | + sa.ForeignKeyConstraint(['project_id'], ['project.id'], ), |
| 37 | + sa.PrimaryKeyConstraint('id'), |
| 38 | + sqlite_autoincrement=True |
| 39 | + ) |
| 40 | + op.create_table('billtags', |
| 41 | + sa.Column('bill_id', sa.Integer(), nullable=False), |
| 42 | + sa.Column('tag_id', sa.Integer(), nullable=False), |
| 43 | + sa.ForeignKeyConstraint(['bill_id'], ['bill.id'], ), |
| 44 | + sa.ForeignKeyConstraint(['tag_id'], ['tag.id'], ), |
| 45 | + sa.PrimaryKeyConstraint('bill_id', 'tag_id'), |
| 46 | + sqlite_autoincrement=True |
| 47 | + ) |
| 48 | + with op.batch_alter_table('bill_version', schema=None) as batch_op: |
| 49 | + batch_op.alter_column('bill_type', |
| 50 | + existing_type=sa.TEXT(), |
| 51 | + type_=sa.Enum('EXPENSE', 'REIMBURSEMENT', name='billtype'), |
| 52 | + existing_nullable=True, |
| 53 | + autoincrement=False) |
| 54 | + |
| 55 | + with op.batch_alter_table('billowers', schema=None) as batch_op: |
| 56 | + batch_op.alter_column('bill_id', |
| 57 | + existing_type=sa.INTEGER(), |
| 58 | + nullable=False) |
| 59 | + batch_op.alter_column('person_id', |
| 60 | + existing_type=sa.INTEGER(), |
| 61 | + nullable=False) |
| 62 | + |
| 63 | + # ### end Alembic commands ### |
| 64 | + |
| 65 | + |
| 66 | +def downgrade(): |
| 67 | + # ### commands auto generated by Alembic - please adjust! ### |
| 68 | + with op.batch_alter_table('billowers', schema=None) as batch_op: |
| 69 | + batch_op.alter_column('person_id', |
| 70 | + existing_type=sa.INTEGER(), |
| 71 | + nullable=True) |
| 72 | + batch_op.alter_column('bill_id', |
| 73 | + existing_type=sa.INTEGER(), |
| 74 | + nullable=True) |
| 75 | + |
| 76 | + with op.batch_alter_table('bill_version', schema=None) as batch_op: |
| 77 | + batch_op.alter_column('bill_type', |
| 78 | + existing_type=sa.Enum('EXPENSE', 'REIMBURSEMENT', name='billtype'), |
| 79 | + type_=sa.TEXT(), |
| 80 | + existing_nullable=True, |
| 81 | + autoincrement=False) |
| 82 | + |
| 83 | + op.drop_table('billtags') |
| 84 | + op.drop_table('tag') |
| 85 | + with op.batch_alter_table('billtags_version', schema=None) as batch_op: |
| 86 | + batch_op.drop_index(batch_op.f('ix_billtags_version_transaction_id')) |
| 87 | + batch_op.drop_index(batch_op.f('ix_billtags_version_operation_type')) |
| 88 | + batch_op.drop_index(batch_op.f('ix_billtags_version_end_transaction_id')) |
| 89 | + |
| 90 | + op.drop_table('billtags_version') |
| 91 | + # ### end Alembic commands ### |
0 commit comments