Don't error when target version has no migrations left to apply - #299
Open
ChrisJr404 wants to merge 1 commit into
Open
Don't error when target version has no migrations left to apply#299ChrisJr404 wants to merge 1 commit into
ChrisJr404 wants to merge 1 commit into
Conversation
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.
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.
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.