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

SetTable fails race detector #226

Open
sobafuchs opened this issue Oct 4, 2022 · 3 comments
Open

SetTable fails race detector #226

sobafuchs opened this issue Oct 4, 2022 · 3 comments

Comments

@sobafuchs
Copy link

The SetTable function is problematic if you have parallel go tests that spin up a new database and run the migrations on each individual one. It fails the go race detector as well. I'm forced to use a TestMain function to do this I guess, but what would you do if you want to set a different migration table in different parallel tests? Is there a particular reason it was chosen to make this essentially a mutable variable on the package itself as opposed to simply passing it as an option to Exec?

@rubenv
Copy link
Owner

rubenv commented Oct 4, 2022

It's for convenience. In unit tests, don't use the globals, use a MigrationSet.

@sobafuchs
Copy link
Author

Is this documented anywhere? Otherwise I'd be happy to create a PR for it.

@rubenv
Copy link
Owner

rubenv commented Oct 5, 2022

Don't think so, please do!

It's just a matter of creating a set:

set := MigrationSet[}

And using that one. instead of the global methods:

set.Exec(...)

This, by the way, has the added benefit of not keeping all migrations in memory after executing. Handy if you're resource-constrained.

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

No branches or pull requests

2 participants