diff --git a/provider_collect.go b/provider_collect.go index 5f14fff13..6e230926c 100644 --- a/provider_collect.go +++ b/provider_collect.go @@ -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, diff --git a/provider_collect_test.go b/provider_collect_test.go index d3ee08a10..d07004a9b 100644 --- a/provider_collect_test.go +++ b/provider_collect_test.go @@ -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)) })