]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Add --splice support to merge command
authorKadir Can Ozden <101993364+bysiber@users.noreply.github.com>
Sun, 22 Feb 2026 15:26:49 +0000 (10:26 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 22 Feb 2026 15:34:45 +0000 (10:34 -0500)
Added ``--splice`` support to the :func:`.merge` command. Previously, the
merge command would suggest using ``--splice`` when attempting to merge
non-head revisions, but the flag was not actually accepted by the command.
The ``splice`` parameter is now available in both the command-line
interface and the :func:`.command.merge` function, matching the existing
support in :func:`.command.revision`.  Pull request courtesy Kadir Can
Ozden.

Fixes: #1712
Closes: #1794
Pull-request: https://github.com/sqlalchemy/alembic/pull/1794
Pull-request-sha: a0f9b6d929b7124fbc9c4c0d4d8191f57a42222d

Change-Id: I12125061777b829b98663adab1701154c6f7c3ac

alembic/command.py
docs/build/unreleased/1712.rst [new file with mode: 0644]
tests/test_command.py

index 4897c0d9c2cfb1995cbb201334401a068bd07a80..2cb94ad189990894c9e0f4698c1c78c664b364e5 100644 (file)
@@ -385,6 +385,7 @@ def merge(
     message: Optional[str] = None,
     branch_label: Optional[_RevIdType] = None,
     rev_id: Optional[str] = None,
+    splice: bool = False,
 ) -> Optional[Script]:
     """Merge two revisions together.  Creates a new migration file.
 
@@ -399,6 +400,11 @@ def merge(
     :param rev_id: hardcoded revision identifier instead of generating a new
      one.
 
+    :param splice: if True, allow the merge to create a new branch point
+     even if the given revisions are not heads.
+
+     .. versionadded:: 1.18.5
+
     .. seealso::
 
         :ref:`branches`
@@ -435,6 +441,7 @@ def merge(
         refresh=True,
         head=revisions,
         branch_labels=branch_label,
+        splice=splice,
         **template_args,  # type:ignore[arg-type]
     )
 
diff --git a/docs/build/unreleased/1712.rst b/docs/build/unreleased/1712.rst
new file mode 100644 (file)
index 0000000..e724f96
--- /dev/null
@@ -0,0 +1,11 @@
+.. change::
+    :tags: usecase, commands
+    :tickets: 1712
+
+    Added ``--splice`` support to the :func:`.merge` command. Previously, the
+    merge command would suggest using ``--splice`` when attempting to merge
+    non-head revisions, but the flag was not actually accepted by the command.
+    The ``splice`` parameter is now available in both the command-line
+    interface and the :func:`.command.merge` function, matching the existing
+    support in :func:`.command.revision`.  Pull request courtesy Kadir Can
+    Ozden.
index 8608ba1845225361b88c4021a6ccf3b75bd3e62f..391a19d00ab4a30720f3ef01545831d06dc40190 100644 (file)
@@ -276,6 +276,38 @@ finally:
 
         assert os.path.exists(rev.path)
 
+    def test_merge_cmd_splice(self):
+        """merge with --splice allows non-head revisions to be merged."""
+        cfg = self.cfg
+        self.a, self.b, self.c = three_rev_fixture(cfg)
+        self.d, self.e, self.f = multi_heads_fixture(
+            cfg, self.a, self.b, self.c
+        )
+        # e and f are heads, but b is not a head.
+        # merging b and c (at least one is not a head) should fail
+        # without splice.
+        with expect_raises_message(
+            util.CommandError,
+            "please specify --splice",
+        ):
+            command.merge(
+                self.cfg,
+                [self.b, self.d],
+                rev_id="should_fail",
+            )
+        # with splice=True, it should succeed
+        command.merge(
+            self.cfg,
+            [self.b, self.d],
+            rev_id="splice_merge",
+            splice=True,
+        )
+        rev = ScriptDirectory.from_config(self.cfg).get_revision(
+            "splice_merge"
+        )
+        assert os.path.exists(rev.path)
+        eq_(rev.module.down_revision, (self.b, self.d))
+
 
 class CurrentTest(_BufMixin, TestBase):
     @classmethod