Part 07 / Topic 1 of 6
Modeling the target
Model for the questions the customer will ask, not for the source system's shape. Acme's dispatchers ask: where is shipment X? what changed today? which shipments for customer Y are delayed? That gives you:
CREATE TABLE shipments (
id TEXT PRIMARY KEY, -- natural key: the customer's shipment id
customer TEXT NOT NULL,
status TEXT NOT NULL,
weight_kg REAL, -- NULL: source had no weight (quarantine told them)
updated_at TEXT NOT NULL -- drives last-write-wins and incremental sync
);
Decisions worth making consciously: use the source's natural key when it is stable and unique (S-2001) — an invented surrogate key just adds a join; keep updated_at from day one (Part 8's incremental sync and this part's upsert both depend on it); and resist modelling fields nobody asked about — every column you load is a column you must keep correct.
Done here? The practice set for Part 7 — 4 exercises with solutions — is on the part page.