mirror of https://github.com/pressly/goose.git
feat: Provider option to disable reading from global registry (#645)
parent
fd6da0315f
commit
0363e19792
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue