//go:build integration package inventory import ( "strings" "testing" ) // **Migration 0108 drops the tables of the delivery plans' machinery** (novox/hq ADR 0539 §17, design 47 release 6, issue 1945): // the record of each send, the assignment generation, the gate's verdicts and the measured durations. The store is built as // the mesh holds it before the migration, with a row in each, and after it the four are gone and what the controller still // keeps stays: the node and its columns, the module, the bus step, the core box and the refused registrations. func TestMigration0108DropsTheTablesOfThePlansMachineryAndKeepsWhatTheControllerStillKeeps(t *testing.T) { inv, migrate := ForTestBefore(t, 108) tables := func() map[string]bool { t.Helper() out := map[string]bool{} for _, row := range inv.QueryForTest(t, `select table_name::text from information_schema.tables where table_schema = 'public'`) { out[strings.Trim(row[0], `"`)] = true } return out } gone := []string{"declaration_send", "assignment_generation", "build_gate", "duration"} before := tables() for _, name := range gone { if !before[name] { t.Fatalf("the table %s is not in the store before the migration", name) } } migrate() after := tables() for _, name := range gone { if after[name] { t.Errorf("the table %s is still in the store", name) } } for _, stays := range []string{"node", "module", "bus_step", "core_box", "build_refused", "controller_schema"} { if !after[stays] { t.Errorf("the table %s is gone", stays) } } // The functions and triggers the tables carried go with them. if rows := inv.QueryForTest(t, `select count(*) from pg_proc where proname = 'raise_assignment_generation'`); rows[0][0] != "0" { t.Errorf("the function raise_assignment_generation is still in the store") } } // **Migration 0109 drops the columns of the node row that kept what a send carried** (ADR 0539 §17, issue 1945): the builds, // the epoch, the summary and the generation. The provisioner's plans stay (0110 drops the rest). func TestMigration0109DropsWhatASendCarriedFromTheNodeRow(t *testing.T) { inv, migrate := ForTestBefore(t, 109) columns := func() map[string]bool { t.Helper() out := map[string]bool{} for _, row := range inv.QueryForTest(t, `select column_name::text from information_schema.columns where table_name = 'node'`) { out[strings.Trim(row[0], `"`)] = true } return out } gone := []string{"sent_builds", "sent_epoch", "sent_summary", "sent_generation"} before := columns() for _, name := range gone { if !before[name] { t.Fatalf("node.%s is not in the store before the migration", name) } } migrate() after := columns() for _, name := range gone { if after[name] { t.Errorf("node.%s is still in the store", name) } } for _, stays := range []string{"sent_provisioning"} { if !after[stays] { t.Errorf("node.%s is gone", stays) } } } // **Migration 0110 drops the digest and time of a send, and the bus users' digest, from the node row** (ADR 0539 §17, issue // 1945): the haves answer what a machine has. The provisioner's plans stay. func TestMigration0110DropsTheDigestOfASendFromTheNodeRow(t *testing.T) { inv, migrate := ForTestBefore(t, 110) columns := func() map[string]bool { t.Helper() out := map[string]bool{} for _, row := range inv.QueryForTest(t, `select column_name::text from information_schema.columns where table_name = 'node'`) { out[strings.Trim(row[0], `"`)] = true } return out } gone := []string{"sent", "sent_at", "sent_bus_users"} before := columns() for _, name := range gone { if !before[name] { t.Fatalf("node.%s is not in the store before the migration", name) } } migrate() after := columns() for _, name := range gone { if after[name] { t.Errorf("node.%s is still in the store", name) } } if !after["sent_provisioning"] { t.Errorf("node.sent_provisioning is gone") } }