From cd94f35483131d541920cbe581280e223684f3c2 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Sat, 21 Sep 2024 17:19:06 +0800 Subject: [PATCH] fix: handle version prefix in globals (#2701) --- pkg/migration/seed.go | 8 ++++++-- pkg/migration/seed_test.go | 4 ++-- pkg/migration/testdata/{globals.sql => 1_globals.sql} | 0 3 files changed, 8 insertions(+), 4 deletions(-) rename pkg/migration/testdata/{globals.sql => 1_globals.sql} (100%) diff --git a/pkg/migration/seed.go b/pkg/migration/seed.go index 79b2dbc22..f299e9f05 100644 --- a/pkg/migration/seed.go +++ b/pkg/migration/seed.go @@ -28,9 +28,13 @@ func SeedGlobals(ctx context.Context, pending []string, conn *pgx.Conn, fsys fs. for _, path := range pending { filename := filepath.Base(path) fmt.Fprintf(os.Stderr, "Seeding globals from %s...\n", filename) - if globals, err := NewMigrationFromFile(path, fsys); err != nil { + globals, err := NewMigrationFromFile(path, fsys) + if err != nil { return err - } else if err := globals.ExecBatch(ctx, conn); err != nil { + } + // Skip inserting to migration history + globals.Version = "" + if err := globals.ExecBatch(ctx, conn); err != nil { return err } } diff --git a/pkg/migration/seed_test.go b/pkg/migration/seed_test.go index cf88a818f..e81d814a9 100644 --- a/pkg/migration/seed_test.go +++ b/pkg/migration/seed_test.go @@ -52,11 +52,11 @@ func TestSeedData(t *testing.T) { }) } -//go:embed testdata/globals.sql +//go:embed testdata/1_globals.sql var testGlobals string func TestSeedGlobals(t *testing.T) { - pending := []string{"testdata/globals.sql"} + pending := []string{"testdata/1_globals.sql"} t.Run("seeds from file", func(t *testing.T) { // Setup mock postgres diff --git a/pkg/migration/testdata/globals.sql b/pkg/migration/testdata/1_globals.sql similarity index 100% rename from pkg/migration/testdata/globals.sql rename to pkg/migration/testdata/1_globals.sql