Skip to content

Commit 8e7c48a

Browse files
committed
fix(migrations): wrap context.get_context() in a function
1 parent a2514a3 commit 8e7c48a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

sc_audit/migrations/versions/0c2f50c4d517_fix_test_table_foreign_keys.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@
1717
branch_labels: str | Sequence[str] | None = None
1818
depends_on: str | Sequence[str] | None = None
1919

20-
# get naming convention from the context
21-
migration_context = context.get_context()
22-
target_metadata = migration_context.opts.get("target_metadata")
23-
assert target_metadata is not None, "Target metadata must be set in the migration context"
24-
naming_convention = target_metadata.naming_convention
20+
21+
def get_naming_convention():
22+
# get naming convention from the context
23+
migration_context = context.get_context()
24+
target_metadata = migration_context.opts.get("target_metadata")
25+
assert target_metadata is not None, "Target metadata must be set in the migration context"
26+
return target_metadata.naming_convention
2527

2628

2729
def upgrade() -> None:
30+
naming_convention = get_naming_convention()
31+
2832
with op.batch_alter_table('test_minted_blocks', schema=None, naming_convention=naming_convention) as batch_op:
2933
batch_op.drop_constraint('test_minted_blocks_vcs_project_id_fkey', type_='foreignkey')
3034
batch_op.create_foreign_key(batch_op.f('test_minted_blocks_vcs_project_id_fkey'), 'test_vcs_projects', ['vcs_project_id'], ['id'])
@@ -51,6 +55,8 @@ def upgrade() -> None:
5155

5256

5357
def downgrade() -> None:
58+
naming_convention = get_naming_convention()
59+
5460
with op.batch_alter_table('test_sinking_txs', schema=None, naming_convention=naming_convention) as batch_op:
5561
batch_op.drop_constraint(batch_op.f('test_sinking_txs_vcs_project_id_fkey'), type_='foreignkey')
5662
batch_op.create_foreign_key(None, 'vcs_projects', ['vcs_project_id'], ['id'])

0 commit comments

Comments
 (0)