Skip to content

migrate: pre-validate --stop-before targets across all sets before applying - #871

Open
webdevsamran wants to merge 1 commit into
simonw:mainfrom
webdevsamran:fix/migrate-prevalidate-stop-before
Open

webdevsamran wants to merge 1 commit into
simonw:mainfrom
webdevsamran:fix/migrate-prevalidate-stop-before

Conversation

@webdevsamran

@webdevsamran webdevsamran commented Sep 21, 2026

Copy link
Copy Markdown

Summary

When running sqlite-utils migrate with multiple migration sets, an already-applied --stop-before target in a subsequent set would raise an error inside Migrations.apply() only after earlier sets had already applied and committed their pending migrations.

This violates the documented contract for --stop-before:

stopping before it is impossible to honor, and no pending migrations are applied

Fixes #870

Solution

In sqlite_utils/cli.py (migrate command), after validating unknown --stop-before migration names, pre-validate across all loaded migration sets upfront that no requested targets have already been applied in the database.

If any matching target is already applied, a ClickException is raised before entering the execution loop, ensuring that no migrations in earlier sets are executed or committed.

Testing


Assisted by AI (Google DeepMind / Antigravity). Researched, verified, and authored with human review.


📚 Documentation preview 📚: https://sqlite-utils--871.org.readthedocs.build/en/871/

…plying

When sqlite-utils migrate is invoked with multiple migration sets, an already-applied --stop-before target in a subsequent set would cause an error inside that set's apply() call only after earlier sets had already executed and committed their pending migrations.

Pre-validate across all loaded migration sets upfront that no requested --stop-before targets have already been applied before entering the application loop, ensuring no pending migrations are applied when an error is raised.

Fixes simonw#870

Signed-off-by: Samran Asif <samranwebdev2000@gmail.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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.

migrate --stop-before commits earlier sets before rejecting an already-applied target

1 participant