agentleFS
salmandevsalmandev/everything-gemini/skills/dbt-transformation/SKILL.md

dbt-transformation

Skill2 starsChanged 28 days agoApache-2.0View on GitHub

Designs, develops, and tests modular SQL data transformations using dbt (data build tool), Jinja macros, semantic layer metrics, automated schema tests, and documentation generation.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Avoid repetitive boilerplate using parameterized Jinja macros:

    line 141

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

dbt Modular Transformation & Data Modeling

This skill guides structuring production-grade ELT pipelines using dbt (Core & Cloud), enforcing modular layer architecture (staging, intermediate, marts), DRY Jinja macros, automated data testing, and incremental table materialization.


⚡ Core Patterns

1. Multi-Layer Dimensional Modeling Architecture

Organize transformations into clean, progressive DAG layers:

models/
├── staging/                     # 1:1 view on raw sources (renaming, casting)
│   ├── stripe/
│   │   ├── _stripe__sources.yml
│   │   ├── _stripe__models.yml
│   │   └── stg_stripe__payments.sql
├── intermediate/                # Business logic joins & window aggregations
│   └── finance/
│       ├── _int_finance__models.yml
│       └── int_payments_pivoted_to_orders.sql
└── marts/                       # Dimensional star schema (facts & dimensions)
    ├── core/
    │   ├── fct_orders.sql
    │   └── dim_customers.sql
    └── marketing/
        └── fct_campaign_conversions.sql

2. Staging Layer Model with CTE Standards

Clean raw source tables into normalized relational types:

-- models/staging/stripe/stg_stripe__payments.sql
with source as (
    select * from {{ source('stripe', 'payment') }}
),

renamed as (
    select
        id as payment_id,
        orderid as order_id,
        paymentmethod as payment_method,
        status as payment_status,
        -- Amount stored in cents; convert to dollars
        round(amount / 100.0, 2) as amount_usd,
        created as created_at
    from source
)

select * from renamed

Declare tests and column descriptions in accompanying YAML:

# models/staging/stripe/_stripe__models.yml
version: 2

models:
  - name: stg_stripe__payments
    description: "Normalized payments table from Stripe webhook ingest."
    columns:
      - name: payment_id
        description: "Primary key for payment events."
        tests:
          - unique
          - not_null
      - name: payment_status
        tests:
          - accepted_values:
              values: ['success', 'fail', 'pending']

3. High-Performance Incremental Fact Table

Process only newly ingested or updated records using is_incremental():

-- models/marts/core/fct_orders.sql
{{
    config(
        materialized='incremental',
        unique_key='order_id',
        incremental_strategy='merge',
        on_schema_change='fail'
    )
}}

with orders as (
    select * from {{ ref('stg_jaffle_shop__orders') }}
    {% if is_incremental() %}
        -- Only query rows created or modified in the last 3 days for backfill resilience
        where order_date >= (select dateadd('day', -3, max(order_date)) from {{ this }})
    {% endif %}
),

payments as (
    select * from {{ ref('stg_stripe__payments') }}
),

order_payments as (
    select
        order_id,
        sum(case when payment_status = 'success' then amount_usd else 0 end) as amount_usd
    from payments
    group by 1
),

final as (
    select
        orders.order_id,
        orders.customer_id,
        orders.order_date,
        orders.status as order_status,
        coalesce(order_payments.amount_usd, 0) as total_amount_usd
    from orders
    left join order_payments on orders.order_id = order_payments.order_id
)

select * from final

4. Custom Jinja Macro for Dynamic Pivoting

Avoid repetitive boilerplate using parameterized Jinja macros:

-- macros/pivot_sum.sql
{% macro pivot_sum(column_name, values_list, aggregate_col='amount_usd') %}
    {% for val in values_list %}
        sum(case when {{ column_name }} = '{{ val }}' then {{ aggregate_col }} else 0 end) as {{ val }}_amount
        {% if not loop.last %},{% endif %}
    {% endfor %}
{% endmacro %}

Usage in intermediate model:

select
    order_id,
    {{ pivot_sum('payment_method', ['credit_card', 'coupon', 'bank_transfer', 'gift_card']) }}
from {{ ref('stg_stripe__payments') }}
group by 1

🎯 Verification & Diagnostics

  1. Compile SQL with Resolved Jinja:
    dbt compile --select fct_orders
  2. Execute Targeted Subgraph:
    dbt run --select +fct_orders       # Run fct_orders and all upstream dependencies
    dbt test --select stg_stripe+      # Test staging models and downstream marts
  3. Build Documentation & DAG Visualizer:
    dbt docs generate && dbt docs serve

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.