-
Notifications
You must be signed in to change notification settings - Fork 517
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
Filter registered migrations by fs dirpath #553
Conversation
Hi @mfridman, can you take a look at this, please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, before the code was including ALL go migrations from the registered global, but with this change we're filtering that global down to only the .go files from the filesystem. Essentially, this...
for _, migration := range registeredGoMigrations {
//
if _, ok := fsGoMigrations[v]; ok {
migrations = append(migrations, migration)
}
}
At first, this seems like a breaking change, but after looking at this a bit closer I don't think it is. The code previously assumed all .go migrations would be in the same folder and thus registered the same way, so that actually doesn't change 🤔
Yeap, that's correct. |
Okay, this seems reasonable to me. Fwiw, this actually makes the implementation match the Lines 104 to 108 in 3d10b39
... where we loop over the "sources" (filesystem), and ensure everything in the filesystem is registered in the global map. In BOTH cases if a versioned filesystem .go migration isn't registered, it'll fail (this is the main thing I was looking for). This is intended to be a guard for users who added a "version"-looking migration file but didn't register it with an
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm.
Perfect, thanks for the review 🙌 . Please merge when ready. |
Unfortunately this was a breaking change for my app. I've been registering migrations that don't exist on the filesystem at all and are added as pure go functions. They now get excluded completely. At least this got caught by the I'll look at moving them to file-based migrations but I would prefer the single-binary approach. |
Ouch, sorry about that @astromechza. To clarify, were you using something like I typically use Go's embed to include the files in the binary itself:
And then However, I could see a world where there is a "pure register function" that simply takes a |
Yup, exactly, we were calling I think the docs do mention using AddMigration directly, and may need to be updated. |
Thanks for your report @astromechza, going to track this issue in #582 I'd like to bring back the ability to register pure go functions without forcing users to embed the source. |
Closes #552.
Filters registered migration by correspondent fs file in the target dir path. This way, the same binary, can run goose multiple times, over different migration directories. Otherwise, all go migrations will run in the first goose run.
This modification shouldn't be a breaking change, at least not semantically. This was the behavior that I was expecting.
This way we are sure that only migrations in the specified directory are applied on a given run.