Fix offline --sql mode incorrectly emitting DROP TABLE for alembic_version#1827
Open
Suchethan021 wants to merge 1 commit into
Open
Fix offline --sql mode incorrectly emitting DROP TABLE for alembic_version#1827Suchethan021 wants to merge 1 commit into
Suchethan021 wants to merge 1 commit into
Conversation
…rsion Running 'stamp base --sql' or 'downgrade <rev>:base --sql' would emit a DROP TABLE alembic_version statement. Online mode never drops the version table (it only deletes rows), so this was an inconsistency introduced in the very early commits of the project. Remove the block from MigrationContext.run_migrations() that emitted the table drop exclusively in --sql mode when all heads were removed. Add an explanatory comment and an additional test covering 'stamp base --sql'. Fixes: sqlalchemy#1822
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Running
alembic stamp base --sqloralembic downgrade <rev>:base --sqlincorrectly emits aDROP TABLE alembic_versionstatement. Online mode never drops the version table — it only deletes rows from it — so this was an inconsistency introduced in a very early commit (2da7f004) before the 0.1 release.The maintainer confirmed this is a bug:
Changes
alembic/runtime/migration.pyRemoved the block in
MigrationContext.run_migrations()that conditionally dropped the version table whenas_sql=Trueand no heads remained. Added an explanatory comment for future readers.tests/test_command.pytest_version_to_noneassertion to expectDROP TABLE alembic_versionis not present in--sqloutput.test_sql_stamp_to_base_no_dropto explicitly cover thestamp base --sqlpath.docs/build/unreleased/1822.rstAdded changelog entry following Alembic'''s per-file changelog convention.
Test results
(Python 3.13.3 / SQLite; DB-specific and
test_post_writeskipped as expected)Fixes #1822