Skip to content

Commit

Permalink
Allow process_revision_directives option to be configurable (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
luolingchun authored Jul 21, 2023
1 parent b3c4b8b commit 821e37f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/flask_migrate/templates/aioflask-multidb/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ def process_revision_directives(context, revision, directives):
directives[:] = []
logger.info('No changes in schema detected.')

conf_args = current_app.extensions['migrate'].configure_args
if conf_args.get("process_revision_directives") is None:
conf_args["process_revision_directives"] = process_revision_directives

for name, rec in engines.items():
rec['sync_connection'] = conn = rec['connection']._sync_connection()
if USE_TWOPHASE:
Expand All @@ -146,8 +150,7 @@ def process_revision_directives(context, revision, directives):
upgrade_token="%s_upgrades" % name,
downgrade_token="%s_downgrades" % name,
target_metadata=get_metadata(name),
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args
**conf_args
)
context.run_migrations(engine_name=name)

Expand Down
7 changes: 5 additions & 2 deletions src/flask_migrate/templates/aioflask/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@ def process_revision_directives(context, revision, directives):
directives[:] = []
logger.info('No changes in schema detected.')

conf_args = current_app.extensions['migrate'].configure_args
if conf_args.get("process_revision_directives") is None:
conf_args["process_revision_directives"] = process_revision_directives

context.configure(
connection=connection,
target_metadata=get_metadata(),
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args
**conf_args
)

with context.begin_transaction():
Expand Down
7 changes: 5 additions & 2 deletions src/flask_migrate/templates/flask-multidb/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ def process_revision_directives(context, revision, directives):
directives[:] = []
logger.info('No changes in schema detected.')

conf_args = current_app.extensions['migrate'].configure_args
if conf_args.get("process_revision_directives") is None:
conf_args["process_revision_directives"] = process_revision_directives

# for the direct-to-DB use case, start a transaction on all
# engines, then run all migrations, then commit all transactions.
engines = {
Expand All @@ -162,8 +166,7 @@ def process_revision_directives(context, revision, directives):
upgrade_token="%s_upgrades" % name,
downgrade_token="%s_downgrades" % name,
target_metadata=get_metadata(name),
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args
**conf_args
)
context.run_migrations(engine_name=name)

Expand Down
7 changes: 5 additions & 2 deletions src/flask_migrate/templates/flask/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,17 @@ def process_revision_directives(context, revision, directives):
directives[:] = []
logger.info('No changes in schema detected.')

conf_args = current_app.extensions['migrate'].configure_args
if conf_args.get("process_revision_directives") is None:
conf_args["process_revision_directives"] = process_revision_directives

connectable = get_engine()

with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=get_metadata(),
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args
**conf_args
)

with context.begin_transaction():
Expand Down
7 changes: 5 additions & 2 deletions tests/custom_template/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,17 @@ def process_revision_directives(context, revision, directives):
directives[:] = []
logger.info('No changes in schema detected.')

conf_args = current_app.extensions['migrate'].configure_args
if conf_args.get("process_revision_directives") is None:
conf_args["process_revision_directives"] = process_revision_directives

connectable = current_app.extensions['migrate'].db.get_engine()

with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args
**conf_args
)

with context.begin_transaction():
Expand Down

0 comments on commit 821e37f

Please sign in to comment.