Document current outlook schema behavior
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
// - weather.forecast_discussion.v1 -> model.WeatherForecastDiscussion
|
||||
// - weather.weather_story.v1 -> model.WeatherStoryRun
|
||||
// - weather.alert.v1 -> model.WeatherAlertRun
|
||||
// - weather.outlook.v1 -> model.WeatherOutlookRun
|
||||
// - weather.outlook.v2 -> model.WeatherOutlookRun
|
||||
//
|
||||
// Parent/child relationships:
|
||||
// - observations.event_id -> observation_present_weather.event_id
|
||||
@@ -21,6 +21,7 @@
|
||||
// - alert_runs.event_id -> alerts.run_event_id
|
||||
// - alerts.(run_event_id, alert_index) -> alert_references.(run_event_id, alert_index)
|
||||
// - outlook_runs.event_id -> outlooks.run_event_id
|
||||
// - outlook_runs.event_id -> outlook_discussions.run_event_id
|
||||
//
|
||||
// Dedupe and retention behavior:
|
||||
// - Parent primary keys (event_id): observations, forecasts, alert_runs, outlook_runs.
|
||||
@@ -39,6 +40,7 @@
|
||||
// - alert_references.as_of
|
||||
// - outlook_runs.as_of
|
||||
// - outlooks.as_of
|
||||
// - outlook_discussions.as_of
|
||||
//
|
||||
// Envelope field mapping (shared parent columns)
|
||||
//
|
||||
@@ -227,6 +229,7 @@
|
||||
// - as_of TIMESTAMPTZ -> payload.asOf
|
||||
// - issued_at TIMESTAMPTZ NULL -> payload.issuedAt
|
||||
// - outlook_count INTEGER -> len(payload.outlooks)
|
||||
// - discussion_count INTEGER -> len(payload.discussions)
|
||||
//
|
||||
// 11. outlooks (PK: run_event_id, outlook_index)
|
||||
//
|
||||
@@ -246,14 +249,22 @@
|
||||
// - issued_at TIMESTAMPTZ -> payload.outlooks[i].issuedAt
|
||||
// - expires_at TIMESTAMPTZ -> payload.outlooks[i].expiresAt
|
||||
// - forecaster TEXT NULL -> payload.outlooks[i].forecaster
|
||||
// - headline TEXT NULL -> payload.outlooks[i].headline
|
||||
// - summary TEXT NULL -> payload.outlooks[i].summary
|
||||
// - discussion TEXT NULL -> payload.outlooks[i].discussion
|
||||
// - source_url TEXT NULL -> payload.outlooks[i].sourceUrl
|
||||
// - image_url TEXT NULL -> payload.outlooks[i].imageUrl
|
||||
// - contains_location BOOLEAN -> payload.outlooks[i].containsLocation
|
||||
// - geometry_json TEXT -> compact JSON payload.outlooks[i].geometry
|
||||
//
|
||||
// 12. outlook_discussions (PK: run_event_id, discussion_index)
|
||||
//
|
||||
// - run_event_id TEXT -> outlook_runs.event_id / payload.discussions[i]
|
||||
// - discussion_index INTEGER -> i (array position in payload.discussions)
|
||||
// - as_of TIMESTAMPTZ -> payload.asOf (copied from parent)
|
||||
// - day INTEGER -> payload.discussions[i].day
|
||||
// - headline TEXT NULL -> payload.discussions[i].headline
|
||||
// - summary TEXT NULL -> payload.discussions[i].summary
|
||||
// - discussion TEXT NULL -> payload.discussions[i].discussion
|
||||
// - updated_at TIMESTAMPTZ NULL -> payload.discussions[i].updatedAt
|
||||
//
|
||||
// Reconstructing canonical JSON payloads
|
||||
//
|
||||
// - WeatherObservation:
|
||||
@@ -274,6 +285,7 @@
|
||||
// ordered by reference_index to rebuild references per alert.
|
||||
//
|
||||
// - WeatherOutlookRun:
|
||||
// read one row from outlook_runs, then join outlooks by run_event_id ordered
|
||||
// by outlook_index to rebuild outlooks.
|
||||
// read one row from outlook_runs, join outlooks by run_event_id ordered by
|
||||
// outlook_index to rebuild outlooks, then join outlook_discussions by
|
||||
// run_event_id ordered by discussion_index to rebuild discussions.
|
||||
package postgres
|
||||
|
||||
33
internal/sinks/postgres/docs_test.go
Normal file
33
internal/sinks/postgres/docs_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDocumentedOutlookDiscussionStorage(t *testing.T) {
|
||||
for _, path := range []string{
|
||||
"../../../docs/integrations/postgres.md",
|
||||
"../../../docs/internal/postgres-sink.md",
|
||||
} {
|
||||
t.Run(path, func(t *testing.T) {
|
||||
raw, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadFile(%s) error = %v", path, err)
|
||||
}
|
||||
doc := string(raw)
|
||||
|
||||
for _, want := range []string{
|
||||
tableOutlookDiscussions,
|
||||
"discussion_count",
|
||||
"discussion_index",
|
||||
"weather.outlook.v2",
|
||||
} {
|
||||
if !strings.Contains(doc, want) {
|
||||
t.Fatalf("%s missing %q", path, want)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user