fix(lagoon): keep Status plugin-only; migrate:status adds the framework sets itself (WR-12)

57a849d made lagoon.Status read migrationSets, which changed its result
for consumers: the framework sets came first and a plugin with no
migrations lost its row. Status is back to its pre-57a849d behaviour.
migrate:status (table and --json) now reads the unexported setStatus,
which lists the framework sets and the plugins from migrationSets, so it
still agrees with migrate --pretend. Both share historyRows.

- TestStatusPluginRows pins Status: plugin rows only, an empty row for a
  plugin with no migrations or no history table, none without HasMigrations
- TestMigrateStatusJSON also checks the table lists the framework sets
- TestTwoPluginMigrationSetsIsolated and TestDocsMigrate are back to the
  plugin-only rows
This commit is contained in:
Jakub Zych
2026-10-22 04:30:36 +02:00
parent f5e9ee508b
commit 139f5e3942
8 changed files with 116 additions and 67 deletions

View File

@@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"reflect"
"slices"
"strings"
"testing"
@@ -334,6 +335,51 @@ func TestMigrateStatusJSON(t *testing.T) {
t.Errorf("%v: pending entries lack \"applied\": false:\n%s", args, out)
}
}
// The table lists the same sets: the framework's own first, in the
// order migrate applies them, then the plugins.
out, errOut, code, _ := runLagoon(t, "development", dsn, plugins, "migrate:status")
if code != bonfire.ExitOK {
t.Fatalf("migrate:status: exit %d\n%s", code, errOut)
}
var sets []string
for _, line := range strings.Split(strings.TrimSpace(out), "\n")[1:] {
sets = append(sets, strings.Fields(line)[0])
}
wantSets := []string{"summercms.attach", "summercms.cabana", DeferredHistoryID, QueueHistoryID, "demo.alpha", "demo.beta"}
if !slices.Equal(sets, wantSets) {
t.Errorf("migrate:status sets = %q, want %q:\n%s", sets, wantSets, out)
}
}
// TestStatusPluginRows: Status lists the plugins only, never the
// framework's own sets (migrate:status adds those itself). Every plugin
// that implements pact.HasMigrations gets a row in plugin order, one with
// no migrations and one whose history table does not exist yet included;
// a plugin without HasMigrations gets none.
func TestStatusPluginRows(t *testing.T) {
db, _ := dedicatedDB(t, "lagoon_status_plugin_rows")
gdb, err := Use(t.Context(), db)
if err != nil {
t.Fatal(err)
}
alpha, beta := pendingPlugins()
empty := migPlugin{id: "demo.empty"}
if err := Migrate(gdb, []party.Plugin{alpha}); err != nil {
t.Fatal(err)
}
rows, err := Status(gdb, []party.Plugin{alpha, empty, stubPlugin{id: "demo.plain"}, beta})
if err != nil {
t.Fatal(err)
}
want := []StatusRow{
{Plugin: "demo.alpha", Table: "summer_migrations_demo_alpha", IDs: []string{"202610210001_create_pending_alpha"}},
{Plugin: "demo.empty", Table: "summer_migrations_demo_empty"},
{Plugin: "demo.beta", Table: "summer_migrations_demo_beta"},
}
if !reflect.DeepEqual(rows, want) {
t.Fatalf("Status = %+v, want %+v", rows, want)
}
}
// TestMigrateAppliedLines (WR-07): migrate's "N applied" lines count what