summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-01-26 10:21:25 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2012-01-26 10:21:25 -0500
commit279f8359031a363e0c43a49dd87ac133eba4f6e9 (patch)
treeba81865093005773815b9312fac2586d4be875fc
parentc03889c9d2729d0fe8946363f32a13fafea90201 (diff)
downloadalembic-279f8359031a363e0c43a49dd87ac133eba4f6e9.tar.gz
- [bug] env.py templates call
connection.close() to better support programmatic usage of commands; use NullPool in conjunction with create_engine() as well so that no connection resources remain afterwards. [#25]
-rw-r--r--CHANGES7
-rw-r--r--alembic/templates/generic/env.py13
-rw-r--r--alembic/templates/multidb/env.py15
-rw-r--r--alembic/templates/pylons/env.py7
4 files changed, 32 insertions, 10 deletions
diff --git a/CHANGES b/CHANGES
index 15b36d1..d48b34d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -26,6 +26,13 @@
the newer script.py.mako scripts.
[#24]
+- [bug] env.py templates call
+ connection.close() to better support
+ programmatic usage of commands; use
+ NullPool in conjunction with create_engine()
+ as well so that no connection resources
+ remain afterwards. [#25]
+
0.1.2
=====
- [bug] fix the config.main() function to honor
diff --git a/alembic/templates/generic/env.py b/alembic/templates/generic/env.py
index 73ce403..755bf4f 100644
--- a/alembic/templates/generic/env.py
+++ b/alembic/templates/generic/env.py
@@ -1,6 +1,6 @@
from __future__ import with_statement
from alembic import context
-from sqlalchemy import engine_from_config
+from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
# this is the Alembic Config object, which provides
@@ -48,7 +48,9 @@ def run_migrations_online():
"""
engine = engine_from_config(
- config.get_section(config.config_ini_section), prefix='sqlalchemy.')
+ config.get_section(config.config_ini_section),
+ prefix='sqlalchemy.',
+ poolclass=pool.NullPool)
connection = engine.connect()
context.configure(
@@ -56,8 +58,11 @@ def run_migrations_online():
target_metadata=target_metadata
)
- with context.begin_transaction():
- context.run_migrations()
+ try:
+ with context.begin_transaction():
+ context.run_migrations()
+ finally:
+ connection.close()
if context.is_offline_mode():
run_migrations_offline()
diff --git a/alembic/templates/multidb/env.py b/alembic/templates/multidb/env.py
index 4df6ae3..8812294 100644
--- a/alembic/templates/multidb/env.py
+++ b/alembic/templates/multidb/env.py
@@ -1,7 +1,7 @@
USE_TWOPHASE = False
from alembic import context
-from sqlalchemy import engine_from_config
+from sqlalchemy import engine_from_config, pool
import re
import sys
@@ -44,7 +44,8 @@ def run_migrations_offline():
engines = {}
for name in re.split(r',\s*', db_names):
engines[name] = rec = {}
- rec['url'] = context.config.get_section_option(name, "sqlalchemy.url")
+ rec['url'] = context.config.get_section_option(name,
+ "sqlalchemy.url")
for name, rec in engines.items():
file_ = "%s.sql" % name
@@ -70,8 +71,10 @@ def run_migrations_online():
engines = {}
for name in re.split(r',\s*', db_names):
engines[name] = rec = {}
- rec['engine'] = engine_from_config(context.config.get_section(name),
- prefix='sqlalchemy.')
+ rec['engine'] = engine_from_config(
+ context.config.get_section(name),
+ prefix='sqlalchemy.',
+ poolclass=pool.NullPool)
for name, rec in engines.items():
engine = rec['engine']
@@ -103,6 +106,10 @@ def run_migrations_online():
for rec in engines.values():
rec['transaction'].rollback()
raise
+ finally:
+ for rec in engines.values():
+ rec['connection'].close()
+
if context.is_offline_mode():
run_migrations_offline()
diff --git a/alembic/templates/pylons/env.py b/alembic/templates/pylons/env.py
index 25832bf..ba8809f 100644
--- a/alembic/templates/pylons/env.py
+++ b/alembic/templates/pylons/env.py
@@ -59,8 +59,11 @@ def run_migrations_online():
target_metadata=target_metadata
)
- with context.begin_transaction():
- context.run_migrations()
+ try:
+ with context.begin_transaction():
+ context.run_migrations()
+ finally:
+ connection.close()
if context.is_offline_mode():
run_migrations_offline()