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

Migrations per environment #413

Open
marcelloh opened this issue Nov 3, 2022 · 7 comments
Open

Migrations per environment #413

marcelloh opened this issue Nov 3, 2022 · 7 comments
Labels

Comments

@marcelloh
Copy link

marcelloh commented Nov 3, 2022

Add possibility to decide if the upcoming migration should run or be skipped

If goose would run a migration, if could always check a function isAllowedMigration(name, content),
just before it wants to run the migration.
If I could override that function, it would be easy to have migrations that would only run on a certain environment.

That would be very helpful.

Or have a way to feed Goose an array of filenames (instead of embedFS), then I can do the same.

So this is about seeding from the moment there is a table, so if any migrations will update fields, add fields, delete fields, the end-result can be tested (and each developer has the same data-set to begin with.

@marcelloh
Copy link
Author

I kind of have this working because of a local version of mapfs, but that's yikes.
I rather feed goose with a slice.

@mfridman
Copy link
Collaborator

If I understand correctly, this is specific to using goose as a library? If so, then there could be a callback function like func () bool, error that you supply and goose calls and if err == nil && ok run the migration, otherwise error or skip?

Or, alternatively, you initialize goose and supply it with the set of migration files instead of the default behavior?

So, the root issue is you'd like control over which files goose applies at rutime?

@marcelloh
Copy link
Author

Yes, that would be ideal

@nikitacrit
Copy link
Contributor

Is it currently possible to skip a specific migration? I can't believe there is no such possibility. This suggestion might help.

@marcelloh
Copy link
Author

Well I made it like that, but not so nicely integrated. A call out to some filter function might help a lot.
(Or to feed a slice would do the trick too.)

@mfridman
Copy link
Collaborator

What do you think about the following feature, when initializing a goose.Provider (something I'm working towards with /v4), there is an option to feed a list of versions to exclude:

// SetExcludeVersions returns a new Options value with ExcludeVersions set to the given value.
// ExcludeVersions is a list of migration versions to exclude when reading migrations from
// the filesystem. This is useful for skipping migrations in tests or development.
//
// Default: include all migrations.
func (o Options) SetExcludeVersions(versions []int64) Options {
	// ...
}

The idea is when creating a goose.Provider you can pass a list of versions:

excludeVersions := []int64{6, 18, 99}
goose.DefaultOptions().
	SetExcludeVersions(excludeVersions)
provider, err := goose.NewProvider(goose.DialectPostgres, db, options)

cc @marcelloh Would this have satisfied your requirement, or is a list of filenames more ergonomic?

@marcelloh
Copy link
Author

I would say that filenames would probably be more flexible, but perhaps the int-versions will do the trick too.
Have to see that.
aka: do as you like it the best, people will adjust to that ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants