-
-
Notifications
You must be signed in to change notification settings - Fork 299
Closed
Labels
Description
Migrated issue, originally created by Dimitry Lukashov
When there are multiple active heads and the alembic_version table has multiple records
Script.as_revision_number() should return a tuple, instead it returns only returns the hex identifier of one of the heads, making EnvironmentContext.get_head_revisions() useless and EnvironmentContext.get_revision_arguments() not very helpful when there are multiple heads.
Here is my proposed solution:
--- a/alembic/runtime/environment.py
+++ b/alembic/runtime/environment.py
@@ -201,8 +201,9 @@ class EnvironmentContext(util.ModuleClsProxy):
``upgrade`` or ``downgrade`` command.
If it was specified as ``head``, the actual
- version number is returned; if specified
- as ``base``, ``None`` is returned.
+ version number is returned; if specified as
+ ``heads`` a tuple of version numbers is returned;
+ if specified as ``base``, ``None`` is returned.
This function does not require that the :class:`.MigrationContext`
has been configured.
diff --git a/alembic/script/base.py b/alembic/script/base.py
index 2e6e0fb..419fce8 100644
--- a/alembic/script/base.py
+++ b/alembic/script/base.py
@@ -228,7 +228,7 @@ class ScriptDirectory(object):
return self.revision_map.get_revision(id_)
def as_revision_number(self, id_):
- """Convert a symbolic revision, i.e. 'head' or 'base', into
+ """Convert a symbolic revision, i.e. 'head', 'heads' or 'base', into
an actual revision number."""
with self._catch_revision_errors():
@@ -237,6 +237,9 @@ class ScriptDirectory(object):
if not rev:
# convert () to None
return None
+ elif id_ == 'heads':
+ # expects a tuple
+ return rev
else:
return rev[0]