add claude skills

This commit is contained in:
@gabriel.pereira
2026-03-26 16:29:53 -03:00
parent 11d3cc66d5
commit 5c4e6075e1
11 changed files with 716 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
---
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_<domain>_<metric>.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('<trf_model_name>')) }}
from {{ ref('<trf_model_name>') }}
```
Option B — add a light filter or derived column:
```sql
select
*,
<derived_column> as <alias>
from {{ ref('<trf_model_name>') }}
where <filter_condition>
```
**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_<entity>.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
<natural_key> as <entity>_key,
<descriptive_field_1>,
<descriptive_field_2>
from {{ ref('<stg_or_trf_model>') }}
where <natural_key> 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.

View File

@@ -0,0 +1,10 @@
-- Dimension model: deduplicated entity list from staging or transform.
-- Provide one row per unique entity (customer, product, employee, etc.)
select distinct
<natural_key> as <entity>_key,
<descriptive_field_1> as <readable_field_1>,
<descriptive_field_2> as <readable_field_2>
from {{ ref('<stg_or_trf_model>') }}
where <natural_key> is not null

View File

@@ -0,0 +1,8 @@
-- Fact model: thin wrapper exposing all columns from a transform model.
-- Most common pattern — use dbt_utils.star() to forward all columns.
select {{ dbt_utils.star(ref('<trf_model_name>')) }}
from {{ ref('<trf_model_name>') }}
-- Optional: add a lightweight filter if needed
-- where is_active = true