Marts (fact & dimension)
All 4 marts in this project are views, not materialized tables — computed on read from stock_int (three of them) or stock_change_history_enriched (the fourth). If you're used to "mart" implying a physically stored, pre-computed table, this project's marts don't work that way.
The three stock_int-derived marts
| Mart | Grain | What it is |
|---|---|---|
stock_make_dim_mart | One row per make_code | Distinct makes from stock_int, surrogate PK MD5(make_code) |
stock_family_dim_mart | One row per (make_code, family_code) | Distinct make/family pairs, PK MD5(make_code || family_code), FK back to the make dim |
stock_fact_mart | One row per vehicle (stock_unique_key) | A reshape of stock_int's current-state snapshot, with surrogate make_pk/family_pk foreign keys and a computed stock_external_identifier (provider_slug:dealer_id:stock_id) |
stock_fact_mart has real referential-integrity tests — not_null + unique on stock_unique_key, and not_null + relationships tests tying make_pk/family_pk back to their respective dimension marts. Both dimension marts have their own not_null + unique tests on their surrogate keys. This is the one place in the whole project with dbt relationships tests actually wired up between models.
The lifecycle mart: a filtered view of the CDC stream, not of stock_int
stock_lifecycle_fact_mart is a different shape entirely — it reads from the CDC branch, not the enrichment branch:
SELECT * FROM {{ ref('stock_change_history_enriched') }}
WHERE is_lifecycle_valid = TRUEOne row per lifecycle event (insert, update, or sold), not one row per current vehicle state. is_lifecycle_valid is what filters out noise: it's only TRUE for valid inserts/updates, or for a "sold" event where the stock was previously valid — this is what stops a record that was never valid in the first place from generating a fake "became sold" event just because it stopped appearing in a batch.
See Stock operational guidelines for how is_sold actually gets set, and Rejection & validation tracking for what "previously valid" is checked against.