Skip to content

Don't error when target version has no migrations left to apply - #299

Open
ChrisJr404 wants to merge 1 commit into
rubenv:masterfrom
ChrisJr404:fix-execversion-noop-when-already-at-version
Open

Don't error when target version has no migrations left to apply#299
ChrisJr404 wants to merge 1 commit into
rubenv:masterfrom
ChrisJr404:fix-execversion-noop-when-already-at-version

Conversation

@ChrisJr404

Copy link
Copy Markdown

Fixes #255.

If you run ExecVersion (or PlanMigrationToVersion) with a target version and the database is already at that version, there are no migrations left to apply. Instead of succeeding as a no-op, planning returned a confusing "unknown migration with version id N in database" error, because the target lookup treats an empty apply list as a missing version.

This skips the target lookup when there's nothing left to apply, so re-running against the current version just succeeds. Added a unit test that migrates up to the latest version and then requests it again (it failed with the old code and passes now).

Only the already-satisfied case changes. Asking for a genuinely unknown version while migrations are still pending still errors as before.

When a version is passed to ExecVersion/PlanMigrationToVersion and the
database is already at that version, there are no migrations left to
apply, but planning returned a misleading "unknown migration with
version id" error instead of a successful no-op. Skip the target lookup
when nothing is left to apply so re-running against the current version
succeeds.
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.

Logic Bug with ExecVersion

1 participant