package postgres import "testing" func TestWeatherPostgresSchemaShape(t *testing.T) { s := PostgresSchema() if s.MapEvent == nil { t.Fatalf("PostgresSchema().MapEvent is nil") } wantTables := map[string]bool{ tableObservations: true, tableObservationPresentWeather: true, tableForecasts: true, tableForecastPeriods: true, tableForecastDiscussions: true, tableForecastDiscussionKeyMessages: true, tableWeatherStoryRuns: true, tableWeatherStories: true, tableAlertRuns: true, tableAlerts: true, tableAlertReferences: true, } if len(s.Tables) != len(wantTables) { t.Fatalf("PostgresSchema().Tables len = %d, want %d", len(s.Tables), len(wantTables)) } seenIndexes := map[string]bool{} for _, tbl := range s.Tables { if !wantTables[tbl.Name] { t.Fatalf("unexpected table %q in schema", tbl.Name) } if tbl.PruneColumn == "" { t.Fatalf("table %q missing prune column", tbl.Name) } for _, idx := range tbl.Indexes { if seenIndexes[idx.Name] { t.Fatalf("duplicate index name %q", idx.Name) } seenIndexes[idx.Name] = true } } } func TestWeatherPostgresSchemaIncludesWeatherStoryColumns(t *testing.T) { runColumns := columnsForTable(t, tableWeatherStoryRuns) if !runColumns["as_of"] { t.Fatalf("%s missing as_of column", tableWeatherStoryRuns) } if !runColumns["story_count"] { t.Fatalf("%s missing story_count column", tableWeatherStoryRuns) } storyColumns := columnsForTable(t, tableWeatherStories) for _, col := range []string{"start_time", "end_time", "updated_at", "title", "description", "alt_text", "priority", "story_order", "download_url"} { if !storyColumns[col] { t.Fatalf("%s missing %s column", tableWeatherStories, col) } } } func columnsForTable(t *testing.T, table string) map[string]bool { t.Helper() schema := PostgresSchema() for _, tbl := range schema.Tables { if tbl.Name != table { continue } cols := make(map[string]bool, len(tbl.Columns)) for _, col := range tbl.Columns { cols[col.Name] = true } return cols } t.Fatalf("missing table %q", table) return nil }