Skip to content

Commit

Permalink
Remove explicit failure in WithDisableGlobalRegistry (#783)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman authored Jun 25, 2024
1 parent 5c5c9b4 commit 7536ecd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Update `WithDisableGlobalRegistry` behavior (#783). If set, this will ignore globally-registered
migrations instead of raising an error. Specifically, the following check is removed:

```go
if len(global) > 0 {
return nil, errors.New("global registry disabled, but provider has registered go migrations")
}
```

This enables creating isolated goose provider(s) in legacy environments where global migrations may
be registered. Without updating this behavior, it would be impossible to use
`WithDisableGlobalRegistry` in combination with `WithGoMigrations`.

## [v3.21.1]

- Add `GetVersions` method to `goose.Provider`, returns the current (max db) version and the latest
Expand Down
10 changes: 4 additions & 6 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,14 @@ func newProvider(
for version, m := range cfg.registered {
versionToGoMigration[version] = m
}
// Return an error if the global registry is explicitly disabled, but there are registered Go
// migrations.
// Skip adding global Go migrations if explicitly disabled.
if cfg.disableGlobalRegistry {
if len(global) > 0 {
return nil, errors.New("global registry disabled, but provider has registered go migrations")
}
// TODO(mf): let's add a warn-level log here to inform users if len(global) > 0. Would like
// to add this once we're on go1.21 and leverage the new slog package.
} else {
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)
return nil, fmt.Errorf("global go migration conflicts with provider-registered go migration with version %d", version)
}
versionToGoMigration[version] = m
}
Expand Down

0 comments on commit 7536ecd

Please sign in to comment.