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

Add goose provider with unimplemented methods #596

Merged
merged 17 commits into from
Oct 7, 2023
Merged

Conversation

mfridman
Copy link
Collaborator

@mfridman mfridman commented Sep 14, 2023

This PR stubs out a Provider in the current /v3 module. It takes the ideas and best parts from #507 and attempts to bring them into the current module in a backwards-compatible way.

I may have been wrong, and cutting a /v4 was probably not the best approach. We can leave the /v4 as a future iteration based on feedback and one last (famous last words) cleanup of the package.

There will be notable differences between the Provider methods and the existing *Migration methods / direct functions, for example:

  • *Provider.Up()
  • *Migration.Up()
  • Up()

provider.go Outdated
// If opts is nil, the default options are used. See ProviderOptions for more information.
//
// Unless otherwise specified, all methods on Provider are safe for concurrent use.
func NewProvider(dialect Dialect, db *sql.DB, opts *ProviderOptions) (*Provider, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@VojtechVitek wdyt about adding the Provider to the /v3 module instead of cutting an entire new major version /v4.

This was the plan for #507, but after a lot of thought, I think we can iterate on the Provider and extend it to support a bunch of features folks have been asking for.

Copy link
Collaborator

Choose a reason for hiding this comment

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

sounds like a good idea :)

// meant to be exhaustive or test every possible database dialect. It is meant to verify the Store
// interface works against a real database.

func TestStore(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This allows us to test the Store implementation in isolation from migrations.

┌───────────────────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │                     PACKAGE                     │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼─────────────────────────────────────────────────┼───────┼──────┼──────┼───────│
│  PASS   │  1.94s  │ github.com/pressly/goose/v3/internal/sqladapter │ 70.8% │  3   │  0   │  0    │
└───────────────────────────────────────────────────────────────────────────────────────────────────┘

There's both a short (sqlite3 with a temp test directory) and long (postgres container) test

// Functional options are used to configure the Provider. See [ProviderOption] for more information.
//
// Unless otherwise specified, all methods on Provider are safe for concurrent use.
func NewProvider(dialect Dialect, db *sql.DB, fsys fs.FS, opts ...ProviderOption) (*Provider, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm fairly happy with the ergonomics of this API.

@mfridman mfridman merged commit ccfb885 into master Oct 7, 2023
8 checks passed
@mfridman mfridman deleted the gh-379-provider branch October 7, 2023 03:53
@mfridman mfridman mentioned this pull request Oct 7, 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.

2 participants