Skip to content
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

fix: collect go migrations #588

Merged
merged 7 commits into from
Aug 27, 2023
Merged

fix: collect go migrations #588

merged 7 commits into from
Aug 27, 2023

Conversation

mfridman
Copy link
Collaborator

@mfridman mfridman commented Aug 26, 2023

Fix #582

This PR reinstates the existing behaviour where users can register Go migrations manually without having the corresponding files on disk, or in the embedded filesystem. This is accomplished using the goose.AddNamedMigration.. set of functions.

// If Go migrations have been registered globally, with [goose.AddNamedMigration...], but there are
// no corresponding .go files in the filesystem, add them to the migrations slice.

Fix #553

This PR also allows registering Go migrations, while filtering them down to only those found in the filesystem based on the specific directory.

// If Go migrations have been registered, and there are .go files in the filesystem dirpath, ONLY
// include those in the migrations slices.

We continue to preserve the behaviour where a valid looking .go file doesn't have a corresponding registered migration raises an error.

// Lastly, if there are .go files in the filesystem but they have not been registered, raise an
// error. This is to prevent users from accidentally adding valid looking Go files to the migrations
// folder without registering them.

I've also added a number of tests to capture all this behaviour. See TestCollectMigrations for more details.

check.Number(t, all[2].Version, 19081)
check.Number(t, all[3].Version, 19082)
})
t.Run("filesystem_registered_with_multiple_dirpath", func(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rafalneves this test aims to capture what I think you're trying to do, but if you could look over this specific subtest that'd be great.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's it. Thanks!

@@ -30,7 +30,7 @@ func CreateWithTemplate(db *sql.DB, dir string, tmpl *template.Template, name, m

if sequential {
// always use DirFS here because it's modifying operation
migrations, err := collectMigrationsFS(osFS{}, dir, minVersion, maxVersion)
migrations, err := collectMigrationsFS(osFS{}, dir, minVersion, maxVersion, registeredGoMigrations)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but both create and fix functions do not need the global registered migrations.

They should only operate on the os filesystem.

@mfridman mfridman merged commit 7011525 into master Aug 27, 2023
8 checks passed
@mfridman mfridman deleted the gh-582 branch August 27, 2023 15:31
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.

Go Migrations don't work
2 participants