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

[WIP] - Adding a provider #378

Closed
wants to merge 20 commits into from
Closed

[WIP] - Adding a provider #378

wants to merge 20 commits into from

Conversation

mfridman
Copy link
Collaborator

@mfridman mfridman commented Jul 6, 2022

I don't intend to merge this branch, simply putting up a PR to show where my thinking is at.

This may be done in a backwards-compatible way, since the entry point to a well-defined struct is goose.NewProvider.

I'll go into more detail (eventually), but the summary is:

  • Add a well-defined Provider struct that can be initizlied independently. No more global state, allowing multiple providers per runtime
  • All methods that apply migrations now support context.Context
  • Decouple dialect from driver name. I think the user should pass a *sql.DB and use whatever driver they want, they just have to match it to one of the supported dialects
  • Move CLI concerns to the CLI, and move package concerns to the package. E.g., the goose library should not log so much as a library
  • Add support for Go functions that accept *sql.DB
  • ... add more
// GoMigration is a go migration func that is run within a transaction.
type GoMigration func(tx *sql.Tx) error

// GoMigrationNoTx is a go migration funt that is run outside a transaction.
type GoMigrationNoTx func(db *sql.DB) error

b.WriteString("\t" + name + "\n")
}
b.WriteString("\n")
b.WriteString("go functions must be registered and built into a custom binary see:\nhttps://github.com/pressly/goose/tree/master/examples/go-migrations")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the existing implementation, we did a "is registered" check in the *Migration.run function.

I think this is too late. Instead, we should fail much earlier when initializing the provider.

What we want to avoid is applying 3 migrations and potentially failing on the 4th if the file was not registered.

This isn't a breaking change per se, the end result is still a failure in both cases. But doing it earlier is safer.

@mfridman
Copy link
Collaborator Author

This PR will be superseded by #484

@mfridman mfridman closed this Mar 21, 2023
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