Skip to content

Commit

Permalink
Reuse engine from Flask-SQLAlchemy (Fixes #343)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Feb 21, 2021
1 parent 3a11cd8 commit 8f8ded8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 20 deletions.
Empty file modified flask_migrate/__init__.py
100755 → 100644
Empty file.
16 changes: 3 additions & 13 deletions flask_migrate/templates/flask-multidb/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand Down
8 changes: 1 addition & 7 deletions flask_migrate/templates/flask/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 8f8ded8

Please sign in to comment.