]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- move resolution of "starting rev" for --sql mode into
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 3 Feb 2015 16:40:40 +0000 (11:40 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 3 Feb 2015 16:51:13 +0000 (11:51 -0500)
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

alembic/command.py
alembic/migration.py
docs/build/changelog.rst
tests/test_offline_environment.py

index 530af17af4bd5353ff945cf380acaae5c446fc21..5ba6d6a89ac872ca79be1b3435d75e1e2d09f418 100644 (file)
@@ -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()
-
-
index 098cf6918799b52c5d80745033e2f18317730981..a2241fdcd5c0edfd4b16a2363f712bb5fc2a88da 100644 (file)
@@ -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(
index 225db4473f9b357359a6e754a34a4dbe6d5ede72..d8d2fa31a340d71902e25d59df3359db55aabe9e 100644 (file)
@@ -6,6 +6,24 @@ Changelog
 .. 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
 
index 684e35093bdd4f3e7ee286e06b17dea5d9631fd9..02e592f52aaa75bd6698c741407b65f428de3e91 100644 (file)
@@ -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)