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

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

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,14 @@ func newProvider(
for version, m := range cfg.registered {
versionToGoMigration[version] = m
}
// Add globally registered Go migrations.
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)
// 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
}
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.
Expand Down
14 changes: 12 additions & 2 deletions provider_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -172,8 +181,9 @@ type config struct {
sessionLocker lock.SessionLocker

// Feature
disableVersioning bool
allowMissing bool
disableVersioning bool
allowMissing bool
disableGlobalRegistry bool
}

type configFunc func(*config) error
Expand Down
Loading