]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
narrow rangenotancestor to exclude target heads already present
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 6 May 2021 16:51:30 +0000 (12:51 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 6 May 2021 16:52:33 +0000 (12:52 -0400)
Fixed regression in new revisioning traversal where "alembic downgrade
base" would fail if the database itself were clean and unversioned;
additionally repairs the case where downgrade would fail if attempting
to downgrade to the current head that is already present.

Change-Id: I581cab5a17f69d82e41eab147ceb27a38fe4ce1d
Fixes: #838
alembic/script/revision.py
docs/build/unreleased/838.rst [new file with mode: 0644]
tests/test_version_traversal.py

index 4db0a7b70cf7291050c9ca90201d0c5c291c2a2b..7fbd670a89c3da1b92e49713d2d2e1c73faa0e02 100644 (file)
@@ -1226,6 +1226,7 @@ class RevisionMap(object):
         active_revisions = set(
             self._get_ancestor_nodes(heads, include_dependencies=True)
         )
+
         # Emit revisions to drop in reverse topological sorted order.
         downgrade_revisions.intersection_update(active_revisions)
 
@@ -1235,8 +1236,13 @@ class RevisionMap(object):
                 active_revisions.difference(self._get_ancestor_nodes(roots))
             )
 
-        if not downgrade_revisions:
+        if (
+            target_revision is not None
+            and not downgrade_revisions
+            and target_revision not in heads
+        ):
             # Empty intersection: target revs are not present.
+
             raise RangeNotAncestorError("Nothing to drop", upper)
 
         return downgrade_revisions, heads
diff --git a/docs/build/unreleased/838.rst b/docs/build/unreleased/838.rst
new file mode 100644 (file)
index 0000000..9977800
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: bug, versioning, regression
+    :tickets: 838
+
+    Fixed regression in new revisioning traversal where "alembic downgrade
+    base" would fail if the database itself were clean and unversioned;
+    additionally repairs the case where downgrade would fail if attempting
+    to downgrade to the current head that is already present.
index aad7cce2d3cf464282c98e9c2c80d2d100eef15f..f224731f0fa9ddfd859e6fdd7c1e7847d3c31d69 100644 (file)
@@ -50,6 +50,14 @@ class RevisionPathTest(MigrationTest):
     def teardown_class(cls):
         clear_staging_env()
 
+    def test_downgrade_base_no_version(self):
+        self._assert_downgrade("base", [], [], set())
+
+    def test_downgrade_to_existing(self):
+        self._assert_downgrade(
+            self.a.revision, [self.a.revision], [], {self.a.revision}
+        )
+
     def test_upgrade_path(self):
         self._assert_upgrade(
             self.e.revision,