fix(schema): distinguish optional ML budget installation from corruption
This commit is contained in:
1 parent
367bfa3a2a
commit
cbcb8a24b4
4 files changed
+64
-1
No files matched your search
@@ -21,7 +21,9 @@ func InspectSchema(ctx context.Context, database *sql.DB) (SchemaInspection, err
|
||||
plans[name] = steps
|
||||
}
|
||||
plans["document-store"] = documentBackfillMigrations
|
||||
components, err := db.InspectSQLiteMigrations(ctx, database, plans)
|
||||
components, err := db.InspectSQLiteMigrationsWithOptional(ctx, database, plans, map[string][]string{
|
||||
"machine-learning-budget": {"ml_daily_budget", "ml_budget_receipts"},
|
||||
})
|
||||
return SchemaInspection{Coverage: "managed-components-only", Components: components, LegacyAreas: []string{
|
||||
"core-bootstrap", "campuses/domains/federation", "auth/ACL/user-space", "outbox/notifications/publication-approval",
|
||||
"City", "tasks/calendars", "periodicals", "search/object-listing/assets/GC",
|
||||
|
||||
@@ -7,6 +7,46 @@ import (
|
||||
"pageswiki/internal/db"
|
||||
)
|
||||
|
||||
func TestSchemaInspectionOptionalMLBudget(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
for _, mode := range []string{"absent", "partial", "installed", "missing-tables"} {
|
||||
t.Run(mode, func(t *testing.T) {
|
||||
s := newSchemaTestStore(t)
|
||||
if mode == "partial" {
|
||||
if _, err := s.DB.Exec(mlBudgetStatements[0]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
} else if mode != "absent" {
|
||||
if err := s.EnsureMLBudgetSchema(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if mode == "missing-tables" {
|
||||
if _, err := s.DB.Exec(`DROP TABLE ml_daily_budget; DROP TABLE ml_budget_receipts`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
report, err := InspectSchema(ctx, s.DB)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
found := false
|
||||
for _, component := range report.Components {
|
||||
if component.Component != "machine-learning-budget" {
|
||||
continue
|
||||
}
|
||||
found = true
|
||||
if (component.State == "current") != (mode == "installed") {
|
||||
t.Fatalf("%s: %+v", mode, component)
|
||||
}
|
||||
}
|
||||
if found != (mode != "absent") {
|
||||
t.Fatalf("optional component visibility: %s %v", mode, found)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSchemaInspectionDoesNotRecoverJobsOrBackfill(t *testing.T) {
|
||||
st := newSchemaTestStore(t)
|
||||
for name := range managedStoreSchemas {
|
||||
|
||||
Reference in new issue
Block a user