feat: Provider option to disable reading from global registry (#645)

pull/646/head
Michael Fridman 2023-11-13 08:50:10 -05:00 committed by GitHub
parent fd6da0315f
commit 0363e19792
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 7 deletions

View File

@ -115,13 +115,15 @@ func newProvider(
for version, m := range cfg.registered {
versionToGoMigration[version] = m
}
// Add globally registered Go migrations.
// Do not add globally registered Go migrations if explicitly disabled.
if !cfg.disableGlobalRegistry {
for version, m := range global {
if _, ok := versionToGoMigration[version]; ok {
return nil, fmt.Errorf("global go migration with version %d previously registered with provider", version)
}
versionToGoMigration[version] = m
}
}
// At this point we have all registered unique Go migrations (if any). We need to merge them
// with SQL migrations from the filesystem.
migrations, err := merge(filesystemSources, versionToGoMigration)

View File

@ -131,6 +131,15 @@ func WithGoMigrations(migrations ...*Migration) ProviderOption {
})
}
// WithDisableGlobalRegistry prevents the provider from registering Go migrations from the global
// registry. By default, goose will register all Go migrations including those registered globally.
func WithDisableGlobalRegistry(b bool) ProviderOption {
return configFunc(func(c *config) error {
c.disableGlobalRegistry = b
return nil
})
}
// WithAllowOutofOrder allows the provider to apply missing (out-of-order) migrations. By default,
// goose will raise an error if it encounters a missing migration.
//
@ -174,6 +183,7 @@ type config struct {
// Feature
disableVersioning bool
allowMissing bool
disableGlobalRegistry bool
}
type configFunc func(*config) error