mirror of https://github.com/status-im/migrate.git
Relaxed constratint that method receiver has to be of Driver interface.
This commit is contained in:
parent
223908f9d2
commit
70b23c3f84
|
@ -8,7 +8,6 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"bufio"
|
||||
"github.com/dimag-jfrog/migrate/driver"
|
||||
"github.com/dimag-jfrog/migrate/file"
|
||||
)
|
||||
|
||||
|
@ -31,7 +30,7 @@ func (e *MethodInvocationFailedError) Error() string {
|
|||
|
||||
|
||||
type Migrator struct {
|
||||
Driver driver.Driver
|
||||
MigrationMethodsReceiver interface{}
|
||||
RollbackOnFailure bool
|
||||
}
|
||||
|
||||
|
@ -73,12 +72,12 @@ func (m *Migrator) Migrate(f file.File, pipe chan interface{}) error {
|
|||
}
|
||||
|
||||
func (m *Migrator) IsValid(methodName string) bool {
|
||||
return reflect.ValueOf(m.Driver).MethodByName(methodName).IsValid()
|
||||
return reflect.ValueOf(m.MigrationMethodsReceiver).MethodByName(methodName).IsValid()
|
||||
}
|
||||
|
||||
func (m *Migrator) Invoke(methodName string) error {
|
||||
name := methodName
|
||||
migrateMethod := reflect.ValueOf(m.Driver).MethodByName(name)
|
||||
migrateMethod := reflect.ValueOf(m.MigrationMethodsReceiver).MethodByName(name)
|
||||
if !migrateMethod.IsValid() {
|
||||
return MissingMethodError(methodName)
|
||||
}
|
||||
|
|
|
@ -232,7 +232,7 @@ func TestMigrate(t *testing.T) {
|
|||
for _, c := range cases {
|
||||
migrator := Migrator{}
|
||||
d := &FakeGoMethodsDriver{Migrator: migrator, InvokedMethods:[]string{}}
|
||||
migrator.Driver = d
|
||||
migrator.MigrationMethodsReceiver = d
|
||||
migrator.RollbackOnFailure = c.expectRollback
|
||||
|
||||
pipe := pipep.New()
|
||||
|
|
|
@ -16,7 +16,7 @@ type GoMethodsMongoDbDriver struct {
|
|||
}
|
||||
|
||||
func (d *GoMethodsMongoDbDriver) Initialize(url string) error {
|
||||
return d.DriverTemplate.Initialize(url, DB_NAME, gomethods.Migrator{Driver: d})
|
||||
return d.DriverTemplate.Initialize(url, DB_NAME, gomethods.Migrator{MigrationMethodsReceiver: d})
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -68,6 +68,7 @@ func RunMigrationAndAssertResult(
|
|||
if !reflect.DeepEqual(expected.Errors, errs) {
|
||||
t.Fatalf("Migration '%s': FAILED\nexpected errors %v\nbut got %v", title, expected.Errors, errs)
|
||||
}
|
||||
t.Logf("Migration '%s': PASSED", title)
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue