mirror of https://github.com/pressly/goose.git
Add source path to Go migrations with file on disk
parent
91e20b290a
commit
c5e0d3cffc
|
@ -133,8 +133,13 @@ func merge(sources *fileSources, registerd map[int64]*Migration) ([]*Migration,
|
|||
// This is almost always a user error.
|
||||
var unregistered []string
|
||||
for _, s := range sources.goSources {
|
||||
if _, ok := registerd[s.Version]; !ok {
|
||||
m, ok := registerd[s.Version]
|
||||
if !ok {
|
||||
unregistered = append(unregistered, s.Path)
|
||||
} else {
|
||||
// Populate the source path for registered Go migrations that have a corresponding file
|
||||
// on disk.
|
||||
m.Source = s.Path
|
||||
}
|
||||
}
|
||||
if len(unregistered) > 0 {
|
||||
|
@ -151,7 +156,7 @@ func merge(sources *fileSources, registerd map[int64]*Migration) ([]*Migration,
|
|||
if existing, ok := migrationLookup[version]; ok {
|
||||
fullpath := r.Source
|
||||
if fullpath == "" {
|
||||
fullpath = "manually registered (no source)"
|
||||
fullpath = "no source path"
|
||||
}
|
||||
return nil, fmt.Errorf("found duplicate migration version %d:\n\texisting:%v\n\tcurrent:%v",
|
||||
version,
|
||||
|
|
|
@ -208,8 +208,8 @@ func TestMerge(t *testing.T) {
|
|||
check.NoError(t, err)
|
||||
check.Number(t, len(migrations), 3)
|
||||
assertMigration(t, migrations[0], newSource(TypeSQL, "00001_foo.sql", 1))
|
||||
assertMigration(t, migrations[1], newSource(TypeGo, "", 2))
|
||||
assertMigration(t, migrations[2], newSource(TypeGo, "", 3))
|
||||
assertMigration(t, migrations[1], newSource(TypeGo, "00002_bar.go", 2))
|
||||
assertMigration(t, migrations[2], newSource(TypeGo, "00003_baz.go", 3))
|
||||
})
|
||||
t.Run("unregistered_all", func(t *testing.T) {
|
||||
_, err := merge(sources, nil)
|
||||
|
@ -280,7 +280,7 @@ func TestMerge(t *testing.T) {
|
|||
check.NoError(t, err)
|
||||
check.Number(t, len(migrations), 4)
|
||||
assertMigration(t, migrations[0], newSource(TypeSQL, "00001_foo.sql", 1))
|
||||
assertMigration(t, migrations[1], newSource(TypeGo, "", 2))
|
||||
assertMigration(t, migrations[1], newSource(TypeGo, "00002_bar.go", 2))
|
||||
assertMigration(t, migrations[2], newSource(TypeGo, "", 3))
|
||||
assertMigration(t, migrations[3], newSource(TypeGo, "", 6))
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue