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: Expose setter for global Go registry #625

Merged
merged 2 commits into from
Oct 28, 2023
Merged

feat: Expose setter for global Go registry #625

merged 2 commits into from
Oct 28, 2023

Conversation

mfridman
Copy link
Collaborator

@mfridman mfridman commented Oct 28, 2023

This PR introduces 2 functions to interact with the global go migration registry. Note, not safe for concurrent use!

Important

Once #379 fully lands, users are encouraged to register Go migrations directly on the goose.Provider, and not globally within the package scope.

Bonus, unlike the init() registration, this setter allows mixing up and down migrations with different transaction levels for the same version. For example, a caller can register an Up function that runs with *sql.Tx (transaction) and a Down function that runs with *sql.DB (no transaction).

Example

// Register one or more migrations globally
err = goose.SetGlobalMigrations(
	goose.Migration{
		Registered:        true,
		Version:           2,
		Source:            "00002_foo.sql",
		Type:              goose.TypeGo,
		UpFnContext:       func(context.Context, *sql.Tx) error { return nil },
		DownFnNoTxContext: func(context.Context, *sql.DB) error { return nil },
	},
)

// Reset global registry
goose.ResetGlobalMigrations()

Supersedes #351

@mfridman mfridman merged commit 20a99fa into master Oct 28, 2023
9 checks passed
@mfridman mfridman deleted the mf-global branch October 28, 2023 20:21
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