From 8f8ded8799c65e2b3490a82b5e3a3953c33c58dd Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Sun, 21 Feb 2021 12:34:25 +0000 Subject: [PATCH] Reuse engine from Flask-SQLAlchemy (Fixes #343) --- flask_migrate/__init__.py | 0 flask_migrate/templates/flask-multidb/env.py | 16 +++------------- flask_migrate/templates/flask/env.py | 8 +------- 3 files changed, 4 insertions(+), 20 deletions(-) mode change 100755 => 100644 flask_migrate/__init__.py diff --git a/flask_migrate/__init__.py b/flask_migrate/__init__.py old mode 100755 new mode 100644 diff --git a/flask_migrate/templates/flask-multidb/env.py b/flask_migrate/templates/flask-multidb/env.py index 79a2cfb..e2dd4da 100644 --- a/flask_migrate/templates/flask-multidb/env.py +++ b/flask_migrate/templates/flask-multidb/env.py @@ -3,9 +3,7 @@ import logging from logging.config import fileConfig -from sqlalchemy import engine_from_config from sqlalchemy import MetaData -from sqlalchemy import pool from flask import current_app from alembic import context @@ -120,20 +118,12 @@ def process_revision_directives(context, revision, directives): # for the direct-to-DB use case, start a transaction on all # engines, then run all migrations, then commit all transactions. engines = { - '': { - 'engine': engine_from_config( - config.get_section(config.config_ini_section), - prefix='sqlalchemy.', - poolclass=pool.NullPool, - ) - } + '': {'engine': current_app.extensions['migrate'].db.engine} } for name in bind_names: engines[name] = rec = {} - rec['engine'] = engine_from_config( - context.config.get_section(name), - prefix='sqlalchemy.', - poolclass=pool.NullPool) + rec['engine'] = current_app.extensions['migrate'].db.get_engine( + app=current_app, bind=name) for name, rec in engines.items(): engine = rec['engine'] diff --git a/flask_migrate/templates/flask/env.py b/flask_migrate/templates/flask/env.py index 8b3fb33..42438a5 100644 --- a/flask_migrate/templates/flask/env.py +++ b/flask_migrate/templates/flask/env.py @@ -3,8 +3,6 @@ import logging from logging.config import fileConfig -from sqlalchemy import engine_from_config -from sqlalchemy import pool from flask import current_app from alembic import context @@ -72,11 +70,7 @@ def process_revision_directives(context, revision, directives): directives[:] = [] logger.info('No changes in schema detected.') - connectable = engine_from_config( - config.get_section(config.config_ini_section), - prefix='sqlalchemy.', - poolclass=pool.NullPool, - ) + connectable = current_app.extensions['migrate'].db.engine with connectable.connect() as connection: context.configure(