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
4 changes: 0 additions & 4 deletions alembic/runtime/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,10 +639,6 @@ def run_migrations(self, **kw: Any) -> None:
run_args=kw,
)

if self.as_sql and not head_maintainer.heads:
assert self.connection is not None
self._version.drop(self.connection)

def _in_connection_transaction(self) -> bool:
try:
meth = self.connection.in_transaction # type:ignore[union-attr]
Expand Down
8 changes: 8 additions & 0 deletions docs/build/unreleased/1822.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. change::
:tags: bug, commands
:tickets: 1822

Fixed SQL output for commands such as ``stamp base --sql`` and
``downgrade ...:base --sql`` to no longer emit ``DROP TABLE`` for the
Alembic version table. This now matches online mode, where Alembic
updates the version rows but does not drop the version table.
7 changes: 6 additions & 1 deletion tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ def test_version_to_none(self):
command.downgrade(self.cfg, "%s:base" % self.c, sql=True)
assert "CREATE TABLE alembic_version" not in buf.getvalue()
assert "INSERT INTO alembic_version" not in buf.getvalue()
assert "DROP TABLE alembic_version" in buf.getvalue()
assert "DROP TABLE alembic_version" not in buf.getvalue()
assert "DROP STEP 3" in buf.getvalue()
assert "DROP STEP 2" in buf.getvalue()
assert "DROP STEP 1" in buf.getvalue()
Expand Down Expand Up @@ -1047,6 +1047,11 @@ def test_sql_stamp_revision_as_kw(self):
in buf.getvalue()
)

def test_sql_stamp_base_does_not_drop_version_table(self):
with capture_context_buffer() as buf:
command.stamp(self.cfg, "base", sql=True)
assert "DROP TABLE alembic_version" not in buf.getvalue()

def test_stamp_argparser_single_rev(self):
cmd = config.CommandLine()
options = cmd.parser.parse_args(["stamp", self.c, "--sql"])
Expand Down