|
| 1 | +"""inspection_images table creation |
| 2 | +
|
| 3 | +Revision ID: 199147664d8e |
| 4 | +Revises: ff7d002a8a12 |
| 5 | +Create Date: 2025-02-18 10:11:33.606897 |
| 6 | +
|
| 7 | +""" |
| 8 | +from alembic import op |
| 9 | +import sqlalchemy as sa |
| 10 | + |
| 11 | + |
| 12 | +# revision identifiers, used by Alembic. |
| 13 | +revision = '199147664d8e' |
| 14 | +down_revision = 'ff7d002a8a12' |
| 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_images_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('sort_order', sa.Integer(), autoincrement=False, nullable=True, comment='The order of images. grouped by the type.'), |
| 25 | + sa.Column('image_type', sa.Enum('PHOTO', 'FIGURE', name='imagetype'), autoincrement=False, nullable=True), |
| 26 | + sa.Column('original_file_name', sa.String(), autoincrement=False, nullable=True, comment='The original filename of the uploaded image'), |
| 27 | + sa.Column('date_taken', sa.DateTime(timezone=True), autoincrement=False, nullable=True, comment='The time of the image when it is captured'), |
| 28 | + sa.Column('taken_by_id', sa.Integer(), autoincrement=False, nullable=True, comment='The unique identifier of the staff who captured the image'), |
| 29 | + sa.Column('caption', sa.String(), autoincrement=False, nullable=True, comment='The caption of the image'), |
| 30 | + sa.Column('url', sa.String(), autoincrement=False, nullable=True, comment='The actual url of the final uploaded image'), |
| 31 | + sa.Column('created_date', sa.DateTime(), autoincrement=False, nullable=True), |
| 32 | + sa.Column('updated_date', sa.DateTime(), autoincrement=False, nullable=True), |
| 33 | + sa.Column('created_by', sa.String(length=100), autoincrement=False, nullable=True), |
| 34 | + sa.Column('updated_by', sa.String(length=100), autoincrement=False, nullable=True), |
| 35 | + sa.Column('is_active', sa.Boolean(), server_default='t', autoincrement=False, nullable=True), |
| 36 | + sa.Column('is_deleted', sa.Boolean(), server_default='f', autoincrement=False, nullable=True), |
| 37 | + sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False), |
| 38 | + sa.Column('end_transaction_id', sa.BigInteger(), nullable=True), |
| 39 | + sa.Column('operation_type', sa.SmallInteger(), nullable=False), |
| 40 | + sa.Column('requirement_id_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 41 | + sa.Column('sort_order_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 42 | + sa.Column('image_type_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 43 | + sa.Column('original_file_name_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 44 | + sa.Column('date_taken_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 45 | + sa.Column('taken_by_id_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 46 | + sa.Column('caption_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 47 | + sa.Column('url_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 48 | + sa.Column('created_date_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 49 | + sa.Column('updated_date_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 50 | + sa.Column('created_by_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 51 | + sa.Column('updated_by_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 52 | + sa.Column('is_active_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 53 | + sa.Column('is_deleted_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False), |
| 54 | + sa.PrimaryKeyConstraint('id', 'transaction_id') |
| 55 | + ) |
| 56 | + with op.batch_alter_table('inspection_req_images_version', schema=None) as batch_op: |
| 57 | + batch_op.create_index(batch_op.f('ix_inspection_req_images_version_end_transaction_id'), ['end_transaction_id'], unique=False) |
| 58 | + batch_op.create_index(batch_op.f('ix_inspection_req_images_version_operation_type'), ['operation_type'], unique=False) |
| 59 | + batch_op.create_index(batch_op.f('ix_inspection_req_images_version_requirement_id'), ['requirement_id'], unique=False) |
| 60 | + batch_op.create_index(batch_op.f('ix_inspection_req_images_version_transaction_id'), ['transaction_id'], unique=False) |
| 61 | + |
| 62 | + op.create_table('inspection_req_images', |
| 63 | + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='The unique identifier'), |
| 64 | + sa.Column('requirement_id', sa.Integer(), nullable=False, comment='The requirement id'), |
| 65 | + sa.Column('sort_order', sa.Integer(), nullable=False, comment='The order of images. grouped by the type.'), |
| 66 | + sa.Column('image_type', sa.Enum('PHOTO', 'FIGURE', name='imagetype'), nullable=False), |
| 67 | + sa.Column('original_file_name', sa.String(), nullable=False, comment='The original filename of the uploaded image'), |
| 68 | + sa.Column('date_taken', sa.DateTime(timezone=True), nullable=False, comment='The time of the image when it is captured'), |
| 69 | + sa.Column('taken_by_id', sa.Integer(), nullable=False, comment='The unique identifier of the staff who captured the image'), |
| 70 | + sa.Column('caption', sa.String(), nullable=True, comment='The caption of the image'), |
| 71 | + sa.Column('url', sa.String(), nullable=False, comment='The actual url of the final uploaded image'), |
| 72 | + sa.Column('created_date', sa.DateTime(), nullable=False), |
| 73 | + sa.Column('updated_date', sa.DateTime(), nullable=True), |
| 74 | + sa.Column('created_by', sa.String(length=100), nullable=False), |
| 75 | + sa.Column('updated_by', sa.String(length=100), nullable=True), |
| 76 | + sa.Column('is_active', sa.Boolean(), server_default='t', nullable=False), |
| 77 | + sa.Column('is_deleted', sa.Boolean(), server_default='f', nullable=False), |
| 78 | + sa.ForeignKeyConstraint(['requirement_id'], ['inspection_requirements.id'], name='inspection_req_images_req_id_fkey'), |
| 79 | + sa.ForeignKeyConstraint(['taken_by_id'], ['staff_users.id'], name='inspection_images_taken_by_fkey'), |
| 80 | + sa.PrimaryKeyConstraint('id') |
| 81 | + ) |
| 82 | + with op.batch_alter_table('inspection_req_images', schema=None) as batch_op: |
| 83 | + batch_op.create_index(batch_op.f('ix_inspection_req_images_requirement_id'), ['requirement_id'], unique=False) |
| 84 | + |
| 85 | + # ### end Alembic commands ### |
| 86 | + |
| 87 | + |
| 88 | +def downgrade(): |
| 89 | + # ### commands auto generated by Alembic - please adjust! ### |
| 90 | + with op.batch_alter_table('inspection_req_images', schema=None) as batch_op: |
| 91 | + batch_op.drop_index(batch_op.f('ix_inspection_req_images_requirement_id')) |
| 92 | + |
| 93 | + op.drop_table('inspection_req_images') |
| 94 | + with op.batch_alter_table('inspection_req_images_version', schema=None) as batch_op: |
| 95 | + batch_op.drop_index(batch_op.f('ix_inspection_req_images_version_transaction_id')) |
| 96 | + batch_op.drop_index(batch_op.f('ix_inspection_req_images_version_requirement_id')) |
| 97 | + batch_op.drop_index(batch_op.f('ix_inspection_req_images_version_operation_type')) |
| 98 | + batch_op.drop_index(batch_op.f('ix_inspection_req_images_version_end_transaction_id')) |
| 99 | + |
| 100 | + op.drop_table('inspection_req_images_version') |
| 101 | + # ### end Alembic commands ### |
0 commit comments