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:
@@ -186,43 +186,18 @@ func TestTwoPluginMigrationSetsIsolated(t *testing.T) {
|
||||
t.Fatalf("idempotent migrate: %v", err)
|
||||
}
|
||||
|
||||
// Status lists the sets Migrate applies (WR-12): the framework sets
|
||||
// first, in migrationSets order, then the plugins.
|
||||
statusOf := func(t *testing.T) (alpha, beta StatusRow) {
|
||||
t.Helper()
|
||||
status, err := Status(gdb, plugins)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
framework := []string{"summercms.attach", "summercms.cabana", DeferredHistoryID, QueueHistoryID}
|
||||
if len(status) != len(framework)+2 {
|
||||
t.Fatalf("status rows = %+v", status)
|
||||
}
|
||||
for i, id := range framework {
|
||||
if status[i].Plugin != id {
|
||||
t.Fatalf("status row %d = %+v, want the framework set %s", i, status[i], id)
|
||||
}
|
||||
}
|
||||
found := map[string]StatusRow{}
|
||||
for _, row := range status[len(framework):] {
|
||||
found[row.Plugin] = row
|
||||
}
|
||||
var ok bool
|
||||
if alpha, ok = found["demo.alpha"]; !ok {
|
||||
t.Fatalf("no demo.alpha row: %+v", status)
|
||||
}
|
||||
if beta, ok = found["demo.beta"]; !ok {
|
||||
t.Fatalf("no demo.beta row: %+v", status)
|
||||
}
|
||||
return alpha, beta
|
||||
status, err := Status(gdb, plugins)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
alphaRow, betaRow := statusOf(t)
|
||||
if alphaRow.Table != "summer_migrations_demo_alpha" || strings.Join(alphaRow.IDs, ",") != "202609170001_create_alpha" {
|
||||
t.Fatalf("alpha status = %+v", alphaRow)
|
||||
if len(status) != 2 {
|
||||
t.Fatalf("status rows = %+v", status)
|
||||
}
|
||||
if betaRow.Table != "summer_migrations_demo_beta" || strings.Join(betaRow.IDs, ",") != "202609170001_create_beta,202609170002_seed_beta" {
|
||||
t.Fatalf("beta status = %+v", betaRow)
|
||||
if status[0].Plugin != "demo.alpha" || status[0].Table != "summer_migrations_demo_alpha" || strings.Join(status[0].IDs, ",") != "202609170001_create_alpha" {
|
||||
t.Fatalf("alpha status = %+v", status[0])
|
||||
}
|
||||
if status[1].Plugin != "demo.beta" || status[1].Table != "summer_migrations_demo_beta" || strings.Join(status[1].IDs, ",") != "202609170001_create_beta,202609170002_seed_beta" {
|
||||
t.Fatalf("beta status = %+v", status[1])
|
||||
}
|
||||
|
||||
if !gdb.Migrator().HasTable("lagoon_alpha") || !gdb.Migrator().HasTable("lagoon_beta") {
|
||||
@@ -250,12 +225,15 @@ func TestTwoPluginMigrationSetsIsolated(t *testing.T) {
|
||||
t.Fatal("schema rollback must not run on the first beta RollbackLast")
|
||||
}
|
||||
|
||||
alphaRow, betaRow = statusOf(t)
|
||||
if strings.Join(alphaRow.IDs, ",") != "202609170001_create_alpha" {
|
||||
t.Fatalf("alpha history changed: %+v", alphaRow)
|
||||
status, err = Status(gdb, plugins)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Join(betaRow.IDs, ",") != "202609170001_create_beta" {
|
||||
t.Fatalf("beta history = %+v", betaRow)
|
||||
if strings.Join(status[0].IDs, ",") != "202609170001_create_alpha" {
|
||||
t.Fatalf("alpha history changed: %+v", status[0])
|
||||
}
|
||||
if strings.Join(status[1].IDs, ",") != "202609170001_create_beta" {
|
||||
t.Fatalf("beta history = %+v", status[1])
|
||||
}
|
||||
|
||||
if err := RollbackLast(gdb, plugins, "demo.beta"); err != nil {
|
||||
@@ -268,12 +246,15 @@ func TestTwoPluginMigrationSetsIsolated(t *testing.T) {
|
||||
t.Fatal("alpha table must survive beta rollback")
|
||||
}
|
||||
|
||||
alphaRow, betaRow = statusOf(t)
|
||||
if len(alphaRow.IDs) != 1 {
|
||||
t.Fatalf("alpha history after beta down = %+v", alphaRow)
|
||||
status, err = Status(gdb, plugins)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(betaRow.IDs) != 0 {
|
||||
t.Fatalf("beta history should be empty, got %+v", betaRow)
|
||||
if len(status[0].IDs) != 1 {
|
||||
t.Fatalf("alpha history after beta down = %+v", status[0])
|
||||
}
|
||||
if len(status[1].IDs) != 0 {
|
||||
t.Fatalf("beta history should be empty, got %+v", status[1])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user