Skip to content

Don't emit DROP of version table in offline mode at base (#1822)#1823

Open
imurodl wants to merge 1 commit into
sqlalchemy:mainfrom
imurodl:fix-1822-offline-stamp-base-drop
Open

Don't emit DROP of version table in offline mode at base (#1822)#1823
imurodl wants to merge 1 commit into
sqlalchemy:mainfrom
imurodl:fix-1822-offline-stamp-base-drop

Conversation

@imurodl

@imurodl imurodl commented Jun 27, 2026

Copy link
Copy Markdown

Fixes #1822.

As diagnosed by @zzzeek in the issue, offline (--sql) mode emitted a DROP TABLE alembic_version when running stamp or downgrade to base, while online mode never drops the version table — an inconsistency dating to the version table's introduction.

This removes the offline-only DROP so both modes behave the same. The version table is still created when it does not exist; only the spurious offline drop is gone.

Tests

  • Updated UpgradeDowngradeStampTest::test_version_to_none to assert the version table is no longer dropped in offline downgrade-to-base.
  • Added UpgradeDowngradeStampTest::test_sql_stamp_to_base_no_drop regressing the exact scenario from the issue (stamp --sql base).
  • Added a changelog entry under docs/build/unreleased/.

Full local run: 1763 passed (the only failures are pre-existing test_post_write.py hook tests unrelated to this change). black + flake8 clean.

When running ``stamp`` or ``downgrade`` to ``base`` in offline ("--sql")
mode, Alembic emitted a ``DROP TABLE alembic_version`` statement, whereas
the same operations in online mode never drop the version table.  This
offline-only DROP, added when the version table was first introduced, was
an inconsistency.  Offline mode now matches online behavior and no longer
drops the version table; the table is still created when it does not exist.

Fixes: sqlalchemy#1822
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stamp command with "base" emits a DROP if --sql mode is present and no head revisions are present

1 participant