Command Palette

Search for a command to run...

Назад к скиллам
скилл № 70797

dbt-modeling

Writing dbt models with proper CTE patterns, SQL structure, and layer-specific templates. Use this skill when writing or refactoring dbt models, implementing…

БесплатноБез исполняемых скриптов
sfc-gh-dflippoот sfc-gh-dflippo★ 35 звёзд на GitHub13 установок в других каталогах

Установить dbt-modeling в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

dbt Modeling

Purpose

Transform AI agents into experts on writing production-quality dbt models, providing guidance on CTE patterns, SQL structure, and best practices for creating maintainable and performant data models across all medallion architecture layers.

When to Use This Skill

Activate this skill when users ask about:

  • Writing or refactoring dbt models
  • Implementing CTE (Common Table Expression) patterns
  • Creating staging, intermediate, or mart models
  • Structuring SQL for readability and maintainability
  • Implementing proper model dependencies with ref() and source()
  • Converting existing SQL to dbt model format
  • Debugging model SQL structure issues

CTE Pattern Structure

All dbt models should follow this consistent CTE pattern for readability and maintainability:

-- Import CTEs (staging and intermediate models)
with customers as (
    select * from {{ ref('stg_customers') }}
),

orders as (
    select * from {{ ref('stg_orders') }}
),

-- Logical CTEs (business logic)
customer_metrics as (
    select
        customer_id,
        count(*) as order_count,
        sum(order_amount) as lifetime_value
    from orders
    group by customer_id
),

-- Final CTE (column selection and standardization)
final as (
    select
        -- Primary key
        customers.customer_id,

        -- Attributes
        customers.customer_name,
        customers.customer_email,

        -- Metrics
        coalesce(customer_metrics.order_count, 0) as lifetime_orders,
        coalesce(customer_metrics.lifetime_value, 0) as lifetime_value,

        -- Metadata
        current_timestamp() as dbt_updated_at

    from customers
    left join customer_metrics
        on customers.customer_id = customer_metrics.customer_id
)

select * from final

Official dbt Documentation: How we structure our dbt projects


Name-Retention Policy

Retain original SQL object names in dbt models. Do not rename source objects to stg_/int_/mart_ prefixes. The dbt model filename and resulting database object should match the original source table or view name (e.g., a source table CUSTOMERS becomes models/bronze/customers.sql, not stg_customers.sql).

When a model requires intermediate transformation steps, use intermediate CTEs within the same model file rather than creating separate int_ prefixed models:

-- models/bronze/customers.sql
-- Keep original name; use internal CTEs for staging logic

with source as (
    select * from {{ source('ecommerce', 'customers') }}
),

-- Intermediate cleaning (NOT a separate int_ model)
cleaned as (
    select
        customer_id,
        trim(first_name) as first_name,
        trim(last_name) as last_name,
        lower(trim(email)) as email
    from source
)

select * from cleaned

This policy ensures downstream consumers (BI tools, other teams, stored procedures) can reference the same object names they already know, reducing migration friction and avoiding a translation layer between logical names and dbt names.


Bronze Layer: Staging Model Template

Purpose: One-to-one with source tables. Clean and standardize only.

Materialization: ephemeral (set at folder level in dbt_project.yml)

Basic Staging Model

-- models/bronze/stg_salesforce__accounts.sql

select
    -- Primary key
    id as account_id,

    -- Attributes
    name as account_name,
    type as account_type,
    industry,

    -- Standardized fields
    upper(trim(email)) as email_clean,
    cast(annual_revenue as number) as annual_revenue,

    -- Metadata
    current_timestamp() as dbt_loaded_at

from {{ source('salesforce', 'accounts') }}

Staging Model with Light Cleaning

-- models/bronze/stg_ecommerce__customers.sql

select
    -- Primary key
    customer_id,

    -- Attributes (cleaned)
    trim(first_name) as first_name,
    trim(last_name) as last_name,
    lower(trim(email)) as email,

    -- Phone standardization
    regexp_replace(phone, '[^0-9]', '') as phone_clean,

    -- Boolean conversions
    case
        when status = 'active' then true
        else false
    end as is_active,

    -- Date standardization
    cast(created_at as timestamp) as created_at,

    -- Metadata
    current_timestamp() as dbt_loaded_at

from {{ source('ecommerce', 'customers') }}

Staging Rules

✅ DO:

  • Use {{ source() }} for source references
  • Rename columns to standard naming conventions
  • Cast data types explicitly
  • Clean data (trim, upper/lower, standardize formats)
  • Add metadata columns (dbt_loaded_at, dbt_updated_at)

❌ DON'T:

  • Join multiple sources
  • Add business logic or calculations
  • Aggregate or group data
  • Filter rows (except for obvious bad data)
  • Hard-code table names

Silver Layer: Intermediate Model Template

Purpose: Reusable business logic, enrichment, and complex transformations.

**Materializa

Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл dbt-modeling?

Writing dbt models with proper CTE patterns, SQL structure, and layer-specific templates. Use this skill when writing or refactoring dbt models, implementing CTE patterns, creating staging/intermediate/mart models, or ensuring proper SQL structure and dependencies.

Как установить скилл dbt-modeling?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл dbt-modeling запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить dbt-modeling с