diff options
Diffstat (limited to 'alembic/templates/generic/env.py')
-rw-r--r-- | alembic/templates/generic/env.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/alembic/templates/generic/env.py b/alembic/templates/generic/env.py index fccd445..280006d 100644 --- a/alembic/templates/generic/env.py +++ b/alembic/templates/generic/env.py @@ -49,22 +49,19 @@ def run_migrations_online(): and associate a connection with the context. """ - engine = engine_from_config( + connectable = engine_from_config( config.get_section(config.config_ini_section), prefix='sqlalchemy.', poolclass=pool.NullPool) - connection = engine.connect() - context.configure( - connection=connection, - target_metadata=target_metadata - ) + with connectable.connect() as connection: + context.configure( + connection=connection, + target_metadata=target_metadata + ) - try: with context.begin_transaction(): context.run_migrations() - finally: - connection.close() if context.is_offline_mode(): run_migrations_offline() |