-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logic Bug with ExecVersion #255
Comments
Would you mind sending a PR with a unit test to illustrate this? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think there's an issue with the logic for determining which migrations to apply when you specify a version here:
https://github.com/rubenv/sql-migrate/blob/master/migrate.go#L669-L684
Expectation
When specifying a version to apply, if we're already at that version, no migrations should be applied and we should continue on successfully.
Reality
If there are no migrations to apply when you specify a version, then there is a vague error thrown about
Unknown migration with version id (your specified version) in database
.Code
Specifically:
Say you have one migration to apply, version 1. The first time you go through this on a database, that migration hasn't been applied, so it's applied and all is good. If you restart though and go back through this, there will be no migrations to apply (the one that's there has already been applied). The issue here is that the loop
for targetIndex < len(toApply)
doesn't execute becausetargetIndex
is 0 andlen(toApply)
is 0. It then falls to the next line that reports it as an error with an unknown migration.The error messages are also pretty ambiguous and misleading. Ex: I spent a while trying to figure out an unknown version in database when my database had no entries yet - turns out it was a bad version specified but since it meant that there were 0 to apply, it resulted in the same error.
Solution
I think all this needs is a check that if
len(toApply)
is 0, then we have 0 migrations to apply (which is ok) and return success.The text was updated successfully, but these errors were encountered: