summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-02-03 11:40:40 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2015-02-03 11:51:13 -0500
commit0955d44f4b93ff520d07253373bb6cb9b25220b5 (patch)
treea7ebbca6ade9d19963e2c18ac00d7e9676454101
parent267063c1b804b34174ab1fc388ccc616655631fd (diff)
downloadalembic-0955d44f4b93ff520d07253373bb6cb9b25220b5.tar.gz
- move resolution of "starting rev" for --sql mode into
get_current_heads() directly; therefore we don't need to do this in alembic.command, which we were doing for stamp but not downgrade/upgrade. The slight change here is that the context.get_starting_revision_argument() method will return an abbreviated starting rev as abbreviated in all cases, including the stamp command, where we previously were converting a stamp argument first, but not for the upgrade or downgrade commands. - Fixed bug where using a partial revision identifier as the "starting revision" in ``--sql`` mode in a downgrade operation would fail to resolve properly. fixes #269
-rw-r--r--alembic/command.py5
-rw-r--r--alembic/migration.py8
-rw-r--r--docs/build/changelog.rst18
-rw-r--r--tests/test_offline_environment.py34
4 files changed, 58 insertions, 7 deletions
diff --git a/alembic/command.py b/alembic/command.py
index 530af17..5ba6d6a 100644
--- a/alembic/command.py
+++ b/alembic/command.py
@@ -330,9 +330,6 @@ def stamp(config, revision, sql=False, tag=None):
if not sql:
raise util.CommandError("Range revision not allowed")
starting_rev, revision = revision.split(':', 2)
- starting_rev = script.get_revision(starting_rev)
- if starting_rev is not None:
- starting_rev = starting_rev.revision
def do_stamp(rev, context):
return script._stamp_revs(revision, rev)
@@ -347,5 +344,3 @@ def stamp(config, revision, sql=False, tag=None):
tag=tag
):
script.run_env()
-
-
diff --git a/alembic/migration.py b/alembic/migration.py
index 098cf69..a2241fd 100644
--- a/alembic/migration.py
+++ b/alembic/migration.py
@@ -64,7 +64,6 @@ class MigrationContext(object):
self.opts = opts
self.dialect = dialect
self.script = opts.get('script')
-
as_sql = opts.get('as_sql', False)
transactional_ddl = opts.get("transactional_ddl")
@@ -229,7 +228,12 @@ class MigrationContext(object):
"""
if self.as_sql:
- return util.to_tuple(self._start_from_rev, default=())
+ start_from_rev = self._start_from_rev
+ if start_from_rev is not None and self.script:
+ start_from_rev = \
+ self.script.get_revision(start_from_rev).revision
+
+ return util.to_tuple(start_from_rev, default=())
else:
if self._start_from_rev:
raise util.CommandError(
diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst
index 225db44..d8d2fa3 100644
--- a/docs/build/changelog.rst
+++ b/docs/build/changelog.rst
@@ -7,6 +7,24 @@ Changelog
:version: 0.7.5
.. change::
+ :tags: bug, commands
+ :tickets: 269
+
+ Fixed bug where using a partial revision identifier as the
+ "starting revision" in ``--sql`` mode in a downgrade operation
+ would fail to resolve properly.
+
+ As a side effect of this change, the
+ :meth:`.EnvironmentContext.get_starting_revision_argument`
+ method will return the "starting" revision in its originally-
+ given "partial" form in all cases, whereas previously when
+ running within the :meth:`.command.stamp` command, it would have
+ been resolved to a full number before passing it to the
+ :class:`.EnvironmentContext`. The resolution of this value to
+ a real revision number has basically been moved to a more fundamental
+ level within the offline migration process.
+
+ .. change::
:tags: feature, commands
Added a new feature :attr:`.Config.attributes`, to help with the use
diff --git a/tests/test_offline_environment.py b/tests/test_offline_environment.py
index 684e350..02e592f 100644
--- a/tests/test_offline_environment.py
+++ b/tests/test_offline_environment.py
@@ -80,6 +80,7 @@ assert context.get_revision_argument() == '%s'
command.stamp(self.cfg, b, sql=True)
command.downgrade(self.cfg, "%s:%s" % (c, b), sql=True)
+
def test_destination_rev_post_context(self):
env_file_fixture("""
context.configure(dialect_name='sqlite')
@@ -175,3 +176,36 @@ assert not context.requires_connection()
command.upgrade(self.cfg, "%s:%s" % (a, d.revision), sql=True)
assert not re.match(r".*-- .*and multiline", buf.getvalue(), re.S | re.M)
+
+ def test_starting_rev_pre_context_abbreviated(self):
+ env_file_fixture("""
+assert context.get_starting_revision_argument() == '%s'
+""" % b[0:4])
+ command.upgrade(self.cfg, "%s:%s" % (b[0:4], c), sql=True)
+ command.stamp(self.cfg, "%s:%s" % (b[0:4], c), sql=True)
+ command.downgrade(self.cfg, "%s:%s" % (b[0:4], a), sql=True)
+
+ def test_destination_rev_pre_context_abbreviated(self):
+ env_file_fixture("""
+assert context.get_revision_argument() == '%s'
+""" % b[0:4])
+ command.upgrade(self.cfg, "%s:%s" % (a, b[0:4]), sql=True)
+ command.stamp(self.cfg, b[0:4], sql=True)
+ command.downgrade(self.cfg, "%s:%s" % (c, b[0:4]), sql=True)
+
+ def test_starting_rev_context_runs_abbreviated(self):
+ env_file_fixture("""
+context.configure(dialect_name='sqlite')
+context.run_migrations()
+""")
+ command.upgrade(self.cfg, "%s:%s" % (b[0:4], c), sql=True)
+ command.downgrade(self.cfg, "%s:%s" % (b[0:4], a), sql=True)
+
+ def test_destination_rev_context_runs_abbreviated(self):
+ env_file_fixture("""
+context.configure(dialect_name='sqlite')
+context.run_migrations()
+""")
+ command.upgrade(self.cfg, "%s:%s" % (a, b[0:4]), sql=True)
+ command.stamp(self.cfg, b[0:4], sql=True)
+ command.downgrade(self.cfg, "%s:%s" % (c, b[0:4]), sql=True)