Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22480 - Part 2 - Migration fix #1645

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pay-api/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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():
Expand Down Expand Up @@ -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
)

Expand Down
4 changes: 4 additions & 0 deletions pay-api/migrations/script.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
93 changes: 93 additions & 0 deletions pay-api/migrations/versions/2024_07_25_4e57f6cf649c_.py
Original file line number Diff line number Diff line change
@@ -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:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arg, will gun this one next PR

batch_op.drop_constraint(None, type_='foreignkey')
batch_op.drop_constraint(None, type_='foreignkey')
# ### end Alembic commands ###
Loading