From 501f8d7fe93aa0846c765df2ad5e53b5f73bfe14 Mon Sep 17 00:00:00 2001 From: Astrid Gealer Date: Sat, 17 Oct 2026 17:02:04 +0100 Subject: [PATCH] test(purchase): hold back later migrations when staging 000127 stagedMigrations ran every migration but 000127 first, so any later migration (#1020's 000128, #1022's 000129) moved the schema past 127 and golang-migrate never applied it on the second run. Stage only migrations that sort before 000127 and add it together with every later one. Closes #1059 Co-Authored-By: Claude Opus 5.5 --- ..._step_ledger_migration_integration_test.go | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/purchase/plan_step_ledger_migration_integration_test.go b/internal/purchase/plan_step_ledger_migration_integration_test.go index 714971fb8..9a068d36e 100644 --- a/internal/purchase/plan_step_ledger_migration_integration_test.go +++ b/internal/purchase/plan_step_ledger_migration_integration_test.go @@ -6,7 +6,6 @@ import ( "context" "os" "path/filepath" - "strings" "testing" "time" @@ -19,8 +18,11 @@ import ( const neverStartedMigration = "000127_never_started_legacy_ramps_to_new" -// stagedMigrations returns a directory holding every migration but the one -// under test, and a func that adds it, so the test runs the real runner twice. +// stagedMigrations returns a directory holding every migration that sorts +// before the one under test, and a func that adds it plus every later +// migration, so the test runs the real runner twice. Later migrations must be +// held back too: golang-migrate never applies a version below the current +// one, so staging them in the first run would skip the target. func stagedMigrations(t *testing.T) (dir string, addTarget func()) { t.Helper() src := rampMigrationsPath() @@ -32,14 +34,22 @@ func stagedMigrations(t *testing.T) (dir string, addTarget func()) { require.NoError(t, readErr) require.NoError(t, os.WriteFile(filepath.Join(dir, name), b, 0o600)) } + var held []string for _, e := range entries { - if filepath.Ext(e.Name()) == ".sql" && !strings.HasPrefix(e.Name(), neverStartedMigration) { + if filepath.Ext(e.Name()) != ".sql" { + continue + } + // Zero-padded version prefixes sort lexically in version order. + if e.Name() < neverStartedMigration { copyFile(e.Name()) + } else { + held = append(held, e.Name()) } } return dir, func() { - copyFile(neverStartedMigration + ".up.sql") - copyFile(neverStartedMigration + ".down.sql") + for _, name := range held { + copyFile(name) + } } }