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

Draft: exclude Go test files from migrations #474

Merged

Conversation

ipoerner
Copy link
Contributor

@ipoerner ipoerner commented Mar 3, 2023

Database migrations reflect a critical part of an application's workflow. Adding tests for individual migrations following Golang's best practices of reusing the original source file name + appending *_test.go seems to be a reasonable choice.

However, reusing an existing file name that starts with a given numeric value and an underscore will cause problems with Goose, as the migration collector treats it as a regular migrations file, hence failing with:

panic: goose: duplicate version N detected:

This change suggests to blocklist any Go source files ending with the suffix *_test.go in order to mitigate this issue. The naming convention for Go migration files is also mentioned in the README.

@ipoerner
Copy link
Contributor Author

ipoerner commented Mar 3, 2023

@mfridman Please excuse me for opening this PR without an issue. I have not found any contrib notes in this repository.

If you think this change is worth getting merged into the main line, I can also add some more tests to migrate.go.

@mfridman
Copy link
Collaborator

mfridman commented Mar 4, 2023

We already exclude named .go files without a version, so excluding _test.go seems reasonable.

Thanks for filing a PR.

@mfridman mfridman merged commit b62288d into pressly:master Mar 4, 2023
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.

2 participants