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

Do takes a context as its first argument #295

Merged
merged 1 commit into from Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion migrator/migrator.go
Expand Up @@ -160,7 +160,7 @@ func (m *Migrator) run(ctx context.Context, migrations []rel.Migration) {
adapter := m.repo.Adapter(ctx)
for _, migration := range migrations {
if fn, ok := migration.(rel.Do); ok {
check(fn(m.repo))
check(fn(ctx, m.repo))
} else {
check(adapter.Apply(ctx, migration))
}
Expand Down
7 changes: 5 additions & 2 deletions schema.go
@@ -1,6 +1,9 @@
package rel

import "strings"
import (
"context"
"strings"
)

// SchemaOp type.
type SchemaOp uint8
Expand Down Expand Up @@ -138,7 +141,7 @@ func (r Raw) internalMigration() {}
func (r Raw) internalTableDefinition() {}

// Do used internally for schema migration.
type Do func(Repository) error
type Do func(context.Context, Repository) error

func (d Do) description() string {
return "run go code"
Expand Down
3 changes: 2 additions & 1 deletion schema_test.go
@@ -1,6 +1,7 @@
package rel

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -221,7 +222,7 @@ func TestDo(t *testing.T) {
schema Schema
)

schema.Do(func(repo Repository) error { return nil })
schema.Do(func(ctx context.Context, repo Repository) error { return nil })
assert.NotNil(t, schema.Migrations[0])
}

Expand Down