Skip to content

Commit

Permalink
Migration's Do takes a context as its first argument (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
youpy committed Jun 22, 2022
1 parent 64492f9 commit 8347a7d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
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

0 comments on commit 8347a7d

Please sign in to comment.