package inventory import ( "strings" "testing" ) // **The move of the chain has a switch, made by the last migration and written by no migration** (ADR 0408 ยง8, issue // 1089): migration 0104 makes the one-row table chain_moved, and does not touch a table of the chain, which a later // delivery drops once the move is read back. func TestMigration0104MakesTheSwitchOfTheChainsMoveAndNothingElse(t *testing.T) { migrations, err := Migrations() if err != nil { t.Fatal(err) } var found bool for _, m := range migrations { if m.Number != 104 { continue } found = true sql := strings.ToLower(m.SQL) if !strings.Contains(sql, "create table chain_moved") || !strings.Contains(sql, "check (only_one)") { t.Errorf("migration 0104 does not make the one-row chain_moved:\n%s", m.SQL) } for _, line := range strings.Split(sql, "\n") { if strings.HasPrefix(strings.TrimSpace(line), "--") { continue } for _, verb := range []string{"drop ", "insert ", "delete ", "update ", "alter "} { if strings.Contains(line, verb) { t.Errorf("migration 0104 does more than make the switch: %q", line) } } } } if !found { t.Fatal("no migration 0104") } }