--- name: dbt_create_mart description: "Step-by-step instructions for creating dbt Mart models (facts and dimensions) as thin wrappers over transform models. Use for any dbt + Snowflake project." --- # Create a dbt Mart Model (Fact or Dimension) Mart models are **thin wrappers** over transform models. They expose clean, BI-ready tables without duplicating business logic. --- ## Fact Model Steps **1. Name the file** - Pattern: `fct__.sql` - Example: `fct_sales_orders.sql`, `fct_ar_open_items.sql` - Lives in `models/marts/facts/` **2. Write a thin SELECT wrapper** Option A — expose all columns (most common): ```sql select {{ dbt_utils.star(ref('')) }} from {{ ref('') }} ``` Option B — add a light filter or derived column: ```sql select *, as from {{ ref('') }} where ``` **3. Materialization** - Default: `view` (inherited from `dbt_project.yml`). - Override to `table` only if the BI tool performs poorly on views. --- ## Dimension Model Steps **1. Name the file** - Pattern: `dim_.sql` - Example: `dim_customers.sql`, `dim_materials.sql` - Lives in `models/marts/dim/` **2. Write the SELECT** - Dimensions are usually deduped/distinct entity lists from staging or transform. ```sql select distinct as _key, , from {{ ref('') }} where is not null ``` **3. Add schema entry** - File: `models/marts/schema.yml` - Every fact: test `unique` + `not_null` on the primary key. - Every dimension: test `unique` + `not_null` on the surrogate/natural key. - Add `relationships` tests on foreign keys in fact models. --- ## Rules | Rule | Detail | |------|--------| | No business logic | Mart = wrapper only; logic belongs in transform | | Materialization | `view` by default; `table` only if needed for BI performance | | Column naming | `snake_case` for marts; inherit from the transform model | | `ref()` only | Always reference the transform model with `{{ ref() }}` | | BI-facing names | Rename columns here if the BI layer needs friendlier names | --- ## Templates See `mart_fct_template.sql` and `mart_dim_template.sql` in this folder.