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: Add goose provider #635

Merged
merged 13 commits into from
Nov 9, 2023
Merged

feat: Add goose provider #635

merged 13 commits into from
Nov 9, 2023

Conversation

mfridman
Copy link
Collaborator

@mfridman mfridman commented Nov 7, 2023

Fix #379.

This PR ports all the provider code from ./internal/provider to package goose. I'll write a blog post or two about the provider features. Briefly, all functionality is now scoped to a *goose.Provider, which enables folks to have multiple *goose.Provider in the same runtime.

The default path should be easy for most users.

  • pick your sql driver (e.g., _ "modernc.org/sqlite")
  • match the dialect (e.g., database.DialectSQLite3)
  • supply a filesystem (e.g., os.DirFS("path/to/migrations"))
    • or register Go migrations with goose.WithGoMigrations
    • or both!

And then run methods on the provider, e.g., results, err := provider.Up(ctx)

Simple example

// Create a sqlite database for testing.
db, err := sql.Open("sqlite", ":memory:")
check.NoError(t, err)
// Create a new goose provider.
provider, err := goose.NewProvider(
	database.DialectSQLite3,
	db,
	os.DirFS("testdata/migrations"),
)
check.NoError(t, err)
// Apply all "pending" migrations.
results, err := provider.Up(context.Background())
check.NoError(t, err)
for _, r := range results {
	fmt.Printf("OK  %s  %s %s\n", truncateDuration(r.Duration), r.Source.Type, r.Source.Path)
}

OK  1.68ms  sql 00001_users_table.sql
OK  1.25ms  sql 00002_posts_table.sql
OK  1.17ms  sql 00003_comments_table.sql
OK  1.03ms  sql 00004_insert_data.sql
OK  1.29ms  sql 00005_posts_view.sql

@mfridman mfridman merged commit 04e12b8 into master Nov 9, 2023
9 checks passed
@mfridman mfridman deleted the gh379-provider branch November 9, 2023 14:23
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.

Adding a goose provider
1 participant