|
| 1 | +"""special fields |
| 2 | +
|
| 3 | +Revision ID: 03791c319e2b |
| 4 | +Revises: 7a42d4f57279 |
| 5 | +Create Date: 2023-12-01 12:39:54.325967 |
| 6 | +
|
| 7 | +""" |
| 8 | +import sqlalchemy as sa |
| 9 | +from alembic import op |
| 10 | +from sqlalchemy.dialects import postgresql |
| 11 | + |
| 12 | + |
| 13 | +# revision identifiers, used by Alembic. |
| 14 | +revision = '03791c319e2b' |
| 15 | +down_revision = '7a42d4f57279' |
| 16 | +branch_labels = None |
| 17 | +depends_on = None |
| 18 | + |
| 19 | + |
| 20 | +def upgrade(): |
| 21 | + # ### commands auto generated by Alembic - please adjust! ### |
| 22 | + op.create_table('special_fields', |
| 23 | + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), |
| 24 | + sa.Column('entity', sa.Enum('PROJECT', 'PROPONENT', 'WORK', name='entityenum'), nullable=False), |
| 25 | + sa.Column('entity_id', sa.Integer(), nullable=False), |
| 26 | + sa.Column('field_name', sa.String(length=100), nullable=False), |
| 27 | + sa.Column('field_value', sa.String(), nullable=False), |
| 28 | + sa.Column('time_range', postgresql.TSTZRANGE(), nullable=False), |
| 29 | + sa.Column('created_by', sa.String(length=255), nullable=True), |
| 30 | + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', CURRENT_TIMESTAMP)"), nullable=True), |
| 31 | + sa.Column('updated_by', sa.String(length=255), nullable=True), |
| 32 | + sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True), |
| 33 | + sa.Column('is_active', sa.Boolean(), server_default='t', nullable=False), |
| 34 | + sa.Column('is_deleted', sa.Boolean(), server_default='f', nullable=False), |
| 35 | + sa.PrimaryKeyConstraint('id') |
| 36 | + ) |
| 37 | + with op.batch_alter_table('special_fields', schema=None) as batch_op: |
| 38 | + batch_op.create_index('entity_field_index', ['entity', 'entity_id', 'field_name', 'time_range'], unique=False) |
| 39 | + |
| 40 | + op.create_table('special_fields_history', |
| 41 | + sa.Column('id', sa.Integer(), autoincrement=False, nullable=False), |
| 42 | + sa.Column('entity', sa.Enum('PROJECT', 'PROPONENT', 'WORK', name='entityenum'), autoincrement=False, nullable=False), |
| 43 | + sa.Column('entity_id', sa.Integer(), autoincrement=False, nullable=False), |
| 44 | + sa.Column('field_name', sa.String(length=100), autoincrement=False, nullable=False), |
| 45 | + sa.Column('field_value', sa.String(), autoincrement=False, nullable=False), |
| 46 | + sa.Column('time_range', postgresql.TSTZRANGE(), autoincrement=False, nullable=False), |
| 47 | + sa.Column('created_by', sa.String(length=255), autoincrement=False, nullable=True), |
| 48 | + sa.Column('created_at', sa.DateTime(timezone=True), autoincrement=False, nullable=True), |
| 49 | + sa.Column('updated_by', sa.String(length=255), autoincrement=False, nullable=True), |
| 50 | + sa.Column('updated_at', sa.DateTime(timezone=True), autoincrement=False, nullable=True), |
| 51 | + sa.Column('is_active', sa.Boolean(), autoincrement=False, nullable=False), |
| 52 | + sa.Column('is_deleted', sa.Boolean(), autoincrement=False, nullable=False), |
| 53 | + sa.Column('pk', sa.Integer(), autoincrement=True, nullable=False), |
| 54 | + sa.Column('during', postgresql.TSTZRANGE(), nullable=True), |
| 55 | + sa.PrimaryKeyConstraint('id', 'pk') |
| 56 | + ) |
| 57 | + with op.batch_alter_table('special_fields_history', schema=None) as batch_op: |
| 58 | + batch_op.create_index('entity_field_history_index', ['entity', 'entity_id', 'field_name', 'time_range'], unique=False) |
| 59 | + |
| 60 | + op.drop_table('project_special_fields') |
| 61 | + with op.batch_alter_table('event_templates', schema=None) as batch_op: |
| 62 | + batch_op.alter_column('visibility', |
| 63 | + existing_type=postgresql.ENUM('MANDATORY', 'OPTIONAL', 'HIDDEN', name='eventtemplatevisibilityenum'), |
| 64 | + comment='Indicate whether the event generated with this template should be autogenerated or available for optional events or added in the back end using actions', |
| 65 | + existing_comment='Indicate whether the event generated with this template should be autogenerated or available for optional events or added in the back end using actions', |
| 66 | + existing_nullable=False) |
| 67 | + |
| 68 | + with op.batch_alter_table('event_templates_history', schema=None) as batch_op: |
| 69 | + batch_op.alter_column('visibility', |
| 70 | + existing_type=postgresql.ENUM('MANDATORY', 'OPTIONAL', 'HIDDEN', name='eventtemplatevisibilityenum'), |
| 71 | + comment='Indicate whether the event generated with this template should be autogenerated or available for optional events or added in the back end using actions', |
| 72 | + existing_comment='Indicate whether the event generated with this template should be autogenerated or available for optional events or added in the back end using actions', |
| 73 | + existing_nullable=False, |
| 74 | + autoincrement=False) |
| 75 | + |
| 76 | + # ### end Alembic commands ### |
| 77 | + |
| 78 | + |
| 79 | +def downgrade(): |
| 80 | + # ### commands auto generated by Alembic - please adjust! ### |
| 81 | + with op.batch_alter_table('event_templates_history', schema=None) as batch_op: |
| 82 | + batch_op.alter_column('visibility', |
| 83 | + existing_type=postgresql.ENUM('MANDATORY', 'OPTIONAL', 'HIDDEN', name='eventtemplatevisibilityenum'), |
| 84 | + comment='Indicate whether the event generated with this template should be autogenerated or available for optional events or added in the back end using actions', |
| 85 | + existing_comment='Indicate whether the event generated with this template should be autogenerated or available for optional events or added in the back end using actions', |
| 86 | + existing_nullable=False, |
| 87 | + autoincrement=False) |
| 88 | + |
| 89 | + with op.batch_alter_table('event_templates', schema=None) as batch_op: |
| 90 | + batch_op.alter_column('visibility', |
| 91 | + existing_type=postgresql.ENUM('MANDATORY', 'OPTIONAL', 'HIDDEN', name='eventtemplatevisibilityenum'), |
| 92 | + comment='Indicate whether the event generated with this template should be autogenerated or available for optional events or added in the back end using actions', |
| 93 | + existing_comment='Indicate whether the event generated with this template should be autogenerated or available for optional events or added in the back end using actions', |
| 94 | + existing_nullable=False) |
| 95 | + |
| 96 | + op.create_table('project_special_fields', |
| 97 | + sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), |
| 98 | + sa.Column('field_name', sa.VARCHAR(length=100), autoincrement=False, nullable=False), |
| 99 | + sa.Column('field_value', sa.VARCHAR(), autoincrement=False, nullable=False), |
| 100 | + sa.Column('time_range', postgresql.TSTZRANGE(), autoincrement=False, nullable=False), |
| 101 | + sa.Column('project_id', sa.INTEGER(), autoincrement=False, nullable=False), |
| 102 | + sa.Column('created_by', sa.VARCHAR(length=255), autoincrement=False, nullable=True), |
| 103 | + sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text("timezone('utc'::text, CURRENT_TIMESTAMP)"), autoincrement=False, nullable=True), |
| 104 | + sa.Column('updated_by', sa.VARCHAR(length=255), autoincrement=False, nullable=True), |
| 105 | + sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True), |
| 106 | + sa.Column('is_active', sa.BOOLEAN(), server_default=sa.text('true'), autoincrement=False, nullable=False), |
| 107 | + sa.Column('is_deleted', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False), |
| 108 | + sa.ForeignKeyConstraint(['project_id'], ['projects.id'], name='project_special_fields_project_id_fkey'), |
| 109 | + sa.PrimaryKeyConstraint('id', name='project_special_fields_pkey') |
| 110 | + ) |
| 111 | + with op.batch_alter_table('special_fields_history', schema=None) as batch_op: |
| 112 | + batch_op.drop_index('entity_field_history_index') |
| 113 | + |
| 114 | + op.drop_table('special_fields_history') |
| 115 | + with op.batch_alter_table('special_fields', schema=None) as batch_op: |
| 116 | + batch_op.drop_index('entity_field_index') |
| 117 | + |
| 118 | + op.drop_table('special_fields') |
| 119 | + # ### end Alembic commands ### |
0 commit comments