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(experimental): shuffle packages & add explicit provider Go func registration #616

Merged
merged 5 commits into from
Oct 15, 2023

Conversation

mfridman
Copy link
Collaborator

@mfridman mfridman commented Oct 15, 2023

Note

All changes are in ./interal. No changes to the core goose package.

The main goal of this PR is to add the ability to register Go migration functions explicitly on the goose.Provider, instead of solely using func init() { goose.AddMigration(..., ...) }. (note, both explicit and init Go migrations are merged together by version).

This is very useful for creating a closure over Go migration functions for DI purposes.

In the process, a few things were refactored and a bunch more tests were added. Of note,

  • Collapse package migrate and package provider into one
  • Remove redundant Go/SQL types
  • Add new type GoMigration to be used with WithGoMigration
  • Add ParseAllFromFS to package sqlparser with tests
// GoMigration is a user-defined Go migration, registered using the option [WithGoMigration].
type GoMigration struct {
	// One of the following must be set:
	Run func(context.Context, *sql.Tx) error
	// -- OR --
	RunNoTx func(context.Context, *sql.DB) error
}

// WithGoMigration registers a Go migration with the given version.
//
// If WithGoMigration is called multiple times with the same version, an error is returned. Both up
// and down functions may be nil. But if set, exactly one of Run or RunNoTx functions must be set.
func WithGoMigration(version int64, up, down *GoMigration) ProviderOption {
	...
}

@mfridman mfridman changed the title feat(experimental): shuffle packages & explicit Go func registration feat(experimental): shuffle packages & add explicit provider Go func registration Oct 15, 2023
@mfridman mfridman mentioned this pull request Oct 14, 2023
@mfridman mfridman merged commit 58f8534 into master Oct 15, 2023
8 checks passed
@mfridman mfridman deleted the gh-379-3 branch October 15, 2023 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant