Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions alembic/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -435,6 +436,7 @@ def nothing(rev, context):
refresh=True,
head=revisions,
branch_labels=branch_label,
splice=splice,
**template_args, # type:ignore[arg-type]
)

Expand Down
2 changes: 1 addition & 1 deletion alembic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def __init__(self, prog: Optional[str] = None) -> None:
"--splice",
dict(
action="store_true",
help="Allow a non-head revision as the 'head' to splice onto",
help="Allow using a non-head revision as a base by disabling head-only validation",
),
),
"depends_on": (
Expand Down
31 changes: 31 additions & 0 deletions tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from alembic.testing.fixtures import capture_engine_context_buffer
from alembic.testing.fixtures import TestBase
from alembic.util import compat
from alembic.util import CommandError
from alembic.util.sqla_compat import _connectable_has_table


Expand Down Expand Up @@ -276,6 +277,36 @@ def test_merge_cmd_revision_environment(self, rev_env):

assert os.path.exists(rev.path)

def test_merge_cmd_with_splice(self):
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
)
assert_raises(
CommandError,
command.merge,
cfg,
[self.a, self.b],
rev_id="merge_no_splice",
splice=False,
)
command.merge(
cfg,
[self.a, self.b],
rev_id="merge_with_splice",
splice=True,
)
script = ScriptDirectory.from_config(cfg).get_revision("merge_with_splice")
assert script is not None
assert os.path.exists(script.path)

with open(script.path, "r", encoding="utf-8") as fp:
contents = fp.read()

assert self.a in contents
assert self.b in contents


class CurrentTest(_BufMixin, TestBase):
@classmethod
Expand Down