summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-05-25 14:16:33 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-05-25 14:16:33 -0400
commitab4a402fdb9bf45ad0990c44fd12ff50d19160f5 (patch)
treeb9b97c6366e936c779fa3fcc7fa38f6ba077a6ce
parente46d5dc1a57a440f685034e08a0cbf80bc048785 (diff)
parenta4c11c2643b64ee7b83ce1e67406738b8ea39857 (diff)
downloadalembic-ab4a402fdb9bf45ad0990c44fd12ff50d19160f5.tar.gz
Merge branch 'add_env_context_and_config_to_migration_context' of https://github.com/msabramo/alembic into t
-rw-r--r--alembic/environment.py1
-rw-r--r--alembic/migration.py14
2 files changed, 13 insertions, 2 deletions
diff --git a/alembic/environment.py b/alembic/environment.py
index f8875a2..c3e7a38 100644
--- a/alembic/environment.py
+++ b/alembic/environment.py
@@ -661,6 +661,7 @@ class EnvironmentContext(object):
connection=connection,
url=url,
dialect_name=dialect_name,
+ environment_context=self,
opts=opts
)
diff --git a/alembic/migration.py b/alembic/migration.py
index e554515..0fffbe5 100644
--- a/alembic/migration.py
+++ b/alembic/migration.py
@@ -58,7 +58,8 @@ class MigrationContext(object):
op.alter_column("mytable", "somecolumn", nullable=True)
"""
- def __init__(self, dialect, connection, opts):
+ def __init__(self, dialect, connection, opts, environment_context=None):
+ self.environment_context = environment_context
self.opts = opts
self.dialect = dialect
self.script = opts.get('script')
@@ -115,6 +116,7 @@ class MigrationContext(object):
connection=None,
url=None,
dialect_name=None,
+ environment_context=None,
opts={},
):
"""Create a new :class:`.MigrationContext`.
@@ -148,7 +150,7 @@ class MigrationContext(object):
else:
raise Exception("Connection, url, or dialect_name is required.")
- return MigrationContext(dialect, connection, opts)
+ return MigrationContext(dialect, connection, opts, environment_context)
def begin_transaction(self, _per_migration=False):
@@ -305,6 +307,14 @@ class MigrationContext(object):
"""
return self.connection
+ @property
+ def config(self):
+ """Return the :class:`.Config` used by the current environment, if any."""
+ if self.environment_context:
+ return self.environment_context.config
+ else:
+ return None
+
def _compare_type(self, inspector_column, metadata_column):
if self._user_compare_type is False:
return False