|
| 1 | +"""enforcement requirement map |
| 2 | +
|
| 3 | +Revision ID: 20afe60273fb |
| 4 | +Revises: 6c3b6755e2dc |
| 5 | +Create Date: 2025-01-10 11:12:08.390578 |
| 6 | +
|
| 7 | +""" |
| 8 | +from alembic import op |
| 9 | +import sqlalchemy as sa |
| 10 | + |
| 11 | + |
| 12 | +# revision identifiers, used by Alembic. |
| 13 | +revision = '20afe60273fb' |
| 14 | +down_revision = '6c3b6755e2dc' |
| 15 | +branch_labels = None |
| 16 | +depends_on = None |
| 17 | + |
| 18 | + |
| 19 | +def upgrade(): |
| 20 | + # ### commands auto generated by Alembic - please adjust! ### |
| 21 | + op.create_table('inspection_req_enforcement_mappings_version', |
| 22 | + sa.Column('id', sa.Integer(), autoincrement=False, nullable=False, comment='The unique identifier'), |
| 23 | + sa.Column('requirement_id', sa.Integer(), autoincrement=False, nullable=True, comment='The requirement id'), |
| 24 | + sa.Column('enforcement_action_id', sa.Integer(), autoincrement=False, nullable=True, comment='The enforcement action taken on the requirement'), |
| 25 | + sa.Column('created_date', sa.DateTime(), autoincrement=False, nullable=True), |
| 26 | + sa.Column('updated_date', sa.DateTime(), autoincrement=False, nullable=True), |
| 27 | + sa.Column('created_by', sa.String(length=100), autoincrement=False, nullable=True), |
| 28 | + sa.Column('updated_by', sa.String(length=100), autoincrement=False, nullable=True), |
| 29 | + sa.Column('is_active', sa.Boolean(), server_default='t', autoincrement=False, nullable=True), |
| 30 | + sa.Column('is_deleted', sa.Boolean(), server_default='f', autoincrement=False, nullable=True), |
| 31 | + sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False), |
| 32 | + sa.Column('end_transaction_id', sa.BigInteger(), nullable=True), |
| 33 | + sa.Column('operation_type', sa.SmallInteger(), nullable=False), |
| 34 | + sa.Column('requirement_id_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 35 | + sa.Column('enforcement_action_id_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 36 | + sa.Column('created_date_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 37 | + sa.Column('updated_date_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 38 | + sa.Column('created_by_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 39 | + sa.Column('updated_by_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 40 | + sa.Column('is_active_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 41 | + sa.Column('is_deleted_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 42 | + sa.PrimaryKeyConstraint('id', 'transaction_id') |
| 43 | + ) |
| 44 | + with op.batch_alter_table('inspection_req_enforcement_mappings_version', schema=None) as batch_op: |
| 45 | + batch_op.create_index(batch_op.f('ix_inspection_req_enforcement_mappings_version_end_transaction_id'), ['end_transaction_id'], unique=False) |
| 46 | + batch_op.create_index(batch_op.f('ix_inspection_req_enforcement_mappings_version_operation_type'), ['operation_type'], unique=False) |
| 47 | + batch_op.create_index(batch_op.f('ix_inspection_req_enforcement_mappings_version_transaction_id'), ['transaction_id'], unique=False) |
| 48 | + |
| 49 | + op.create_table('inspection_req_enforcement_mappings', |
| 50 | + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='The unique identifier'), |
| 51 | + sa.Column('requirement_id', sa.Integer(), nullable=False, comment='The requirement id'), |
| 52 | + sa.Column('enforcement_action_id', sa.Integer(), nullable=True, comment='The enforcement action taken on the requirement'), |
| 53 | + sa.Column('created_date', sa.DateTime(), nullable=False), |
| 54 | + sa.Column('updated_date', sa.DateTime(), nullable=True), |
| 55 | + sa.Column('created_by', sa.String(length=100), nullable=False), |
| 56 | + sa.Column('updated_by', sa.String(length=100), nullable=True), |
| 57 | + sa.Column('is_active', sa.Boolean(), server_default='t', nullable=False), |
| 58 | + sa.Column('is_deleted', sa.Boolean(), server_default='f', nullable=False), |
| 59 | + sa.ForeignKeyConstraint(['enforcement_action_id'], ['enforcement_action_options.id'], name='insepction_req_enf_map_fkey'), |
| 60 | + sa.ForeignKeyConstraint(['requirement_id'], ['inspection_requirements.id'], name='inspection_req_enf_map_req_id_fkey'), |
| 61 | + sa.PrimaryKeyConstraint('id') |
| 62 | + ) |
| 63 | + with op.batch_alter_table('inspection_requirements', schema=None) as batch_op: |
| 64 | + batch_op.create_index('unique_non_deleted_sort_order', ['inspection_id', 'sort_order'], unique=True, postgresql_where=sa.text('is_deleted IS false')) |
| 65 | + batch_op.drop_constraint('insepction_requirements_enforcement_action_fkey', type_='foreignkey') |
| 66 | + batch_op.drop_column('enforcement_action_id') |
| 67 | + |
| 68 | + with op.batch_alter_table('inspection_requirements_version', schema=None) as batch_op: |
| 69 | + batch_op.drop_column('enforcement_action_id') |
| 70 | + batch_op.drop_column('enforcement_action_id_mod') |
| 71 | + |
| 72 | + # ### end Alembic commands ### |
| 73 | + |
| 74 | + |
| 75 | +def downgrade(): |
| 76 | + # ### commands auto generated by Alembic - please adjust! ### |
| 77 | + with op.batch_alter_table('inspection_requirements_version', schema=None) as batch_op: |
| 78 | + batch_op.add_column(sa.Column('enforcement_action_id_mod', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False)) |
| 79 | + batch_op.add_column(sa.Column('enforcement_action_id', sa.INTEGER(), autoincrement=False, nullable=True, comment='The enforcement action taken on the requirement')) |
| 80 | + |
| 81 | + with op.batch_alter_table('inspection_requirements', schema=None) as batch_op: |
| 82 | + batch_op.add_column(sa.Column('enforcement_action_id', sa.INTEGER(), autoincrement=False, nullable=True, comment='The enforcement action taken on the requirement')) |
| 83 | + batch_op.create_foreign_key('insepction_requirements_enforcement_action_fkey', 'enforcement_action_options', ['enforcement_action_id'], ['id']) |
| 84 | + batch_op.drop_index('unique_non_deleted_sort_order', postgresql_where=sa.text('is_deleted IS false')) |
| 85 | + |
| 86 | + op.drop_table('inspection_req_enforcement_mappings') |
| 87 | + with op.batch_alter_table('inspection_req_enforcement_mappings_version', schema=None) as batch_op: |
| 88 | + batch_op.drop_index(batch_op.f('ix_inspection_req_enforcement_mappings_version_transaction_id')) |
| 89 | + batch_op.drop_index(batch_op.f('ix_inspection_req_enforcement_mappings_version_operation_type')) |
| 90 | + batch_op.drop_index(batch_op.f('ix_inspection_req_enforcement_mappings_version_end_transaction_id')) |
| 91 | + |
| 92 | + op.drop_table('inspection_req_enforcement_mappings_version') |
| 93 | + # ### end Alembic commands ### |
0 commit comments