diff --git a/pay-api/migrations/env.py b/pay-api/migrations/env.py index bad99fb09..c5e65e04a 100644 --- a/pay-api/migrations/env.py +++ b/pay-api/migrations/env.py @@ -41,9 +41,9 @@ def get_list_from_config(config, key): exclude_tables = get_list_from_config(config, "exclude_tables") -def include_name(name, type_, parent_names): +def include_object(object, name, type_, reflected, compare_to): return not (type_ == 'table' and name in exclude_tables) - + def run_migrations_offline(): """Run migrations in 'offline' mode. @@ -58,7 +58,7 @@ def run_migrations_offline(): """ url = config.get_main_option("sqlalchemy.url") context.configure( - url=url, target_metadata=target_metadata, literal_binds=True, compare_type=True, include_name=include_name + url=url, target_metadata=target_metadata, literal_binds=True, compare_type=True, include_object=include_object ) with context.begin_transaction(): @@ -94,7 +94,7 @@ def process_revision_directives(context, revision, directives): connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, - include_name=include_name, + include_object=include_object, **current_app.extensions['migrate'].configure_args ) diff --git a/pay-api/migrations/script.py.mako b/pay-api/migrations/script.py.mako index 2c0156303..15d4ac057 100644 --- a/pay-api/migrations/script.py.mako +++ b/pay-api/migrations/script.py.mako @@ -10,6 +10,10 @@ import sqlalchemy as sa ${imports if imports else ""} # revision identifiers, used by Alembic. +# Note you may see foreign keys with distribution_codes_history +# For disbursement_distribution_code_id, service_fee_distribution_code_id +# Please ignore those lines and don't include in migration. + revision = ${repr(up_revision)} down_revision = ${repr(down_revision)} branch_labels = ${repr(branch_labels)} diff --git a/pay-api/migrations/versions/2024_07_25_4e57f6cf649c_.py b/pay-api/migrations/versions/2024_07_25_4e57f6cf649c_.py new file mode 100644 index 000000000..0cb25159d --- /dev/null +++ b/pay-api/migrations/versions/2024_07_25_4e57f6cf649c_.py @@ -0,0 +1,93 @@ +""" + +Revision ID: 4e57f6cf649c +Revises: f9c15c7f29f5 +Create Date: 2024-07-25 16:03:51.968355 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '4e57f6cf649c' +down_revision = 'f9c15c7f29f5' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.execute('DROP SEQUENCE IF EXISTS eft_refund_email_list_id_seq CASCADE') + op.execute('DROP TABLE IF EXISTS eft_refund_email_list') + op.create_table('eft_refund_email_list', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('first_name', sa.String(25), nullable=True), + sa.Column('last_name', sa.String(25), nullable=True), + sa.Column('email', sa.String(25), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + + with op.batch_alter_table('eft_credit_invoice_links', schema=None) as batch_op: + batch_op.alter_column('status_code', + existing_type=sa.VARCHAR(length=25), + nullable=False) + + with op.batch_alter_table('eft_refunds', schema=None) as batch_op: + batch_op.alter_column('comment', + existing_type=sa.VARCHAR(), + nullable=False) + + with op.batch_alter_table('ejv_links', schema=None) as batch_op: + batch_op.alter_column('link_type', + existing_type=sa.VARCHAR(length=20), + type_=sa.String(length=50), + existing_nullable=True) + batch_op.drop_index('ix_ejv_invoice_links_ejv_header_id') + batch_op.drop_index('ix_ejv_links_link_type_link_id') + batch_op.create_index(batch_op.f('ix_ejv_links_ejv_header_id'), ['ejv_header_id'], unique=False) + batch_op.create_index(batch_op.f('ix_ejv_links_link_id'), ['link_id'], unique=False) + batch_op.create_index(batch_op.f('ix_ejv_links_link_type'), ['link_type'], unique=False) + + with op.batch_alter_table('refunds_partial', schema=None) as batch_op: + batch_op.alter_column('disbursement_date', + existing_type=sa.DATE(), + type_=sa.DateTime(), + existing_nullable=True) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('refunds_partial', schema=None) as batch_op: + batch_op.alter_column('disbursement_date', + existing_type=sa.DateTime(), + type_=sa.DATE(), + existing_nullable=True) + + with op.batch_alter_table('ejv_links', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_ejv_links_link_type')) + batch_op.drop_index(batch_op.f('ix_ejv_links_link_id')) + batch_op.drop_index(batch_op.f('ix_ejv_links_ejv_header_id')) + batch_op.create_index('ix_ejv_links_link_type_link_id', ['link_type', 'link_id'], unique=False) + batch_op.create_index('ix_ejv_invoice_links_ejv_header_id', ['ejv_header_id'], unique=False) + batch_op.alter_column('link_type', + existing_type=sa.String(length=50), + type_=sa.VARCHAR(length=20), + existing_nullable=True) + + with op.batch_alter_table('eft_refunds', schema=None) as batch_op: + batch_op.alter_column('comment', + existing_type=sa.VARCHAR(), + nullable=True) + + with op.batch_alter_table('eft_credit_invoice_links', schema=None) as batch_op: + batch_op.alter_column('status_code', + existing_type=sa.VARCHAR(length=25), + nullable=True) + + with op.batch_alter_table('distribution_codes_history', schema=None) as batch_op: + batch_op.drop_constraint(None, type_='foreignkey') + batch_op.drop_constraint(None, type_='foreignkey') + # ### end Alembic commands ###