<< All versions
Skill v1.0.1
currentAutomated scan100/100majesticlabs-dev/majestic-marketplace/dbt-coder
3 files
──Details
PublishedMay 17, 2026 at 05:48 AM
Content Hashsha256:450f6c5fb8cc90e2...
Git SHA32a021027f2b
Bump Typepatch
──Files
Files (1 file, 6.7 KB)
SKILL.md6.7 KBactive
SKILL.md · 360 lines · 6.7 KB
version: "1.0.1" name: dbt-coder description: dbt (data build tool) patterns for model organization, incremental strategies, and testing. allowed-tools: Read Write Edit Grep Glob Bash
dbt-Coder
Patterns for dbt (data build tool) transform layer development.
Project Structure
my_dbt_project/├── dbt_project.yml├── profiles.yml├── models/│ ├── staging/ # 1:1 with sources, light transforms│ │ ├── stg_orders.sql│ │ └── _staging.yml│ ├── intermediate/ # Joins, business logic│ │ └── int_orders_enriched.sql│ └── marts/ # Final consumption layer│ ├── finance/│ │ └── fct_revenue.sql│ └── marketing/│ └── dim_customers.sql├── seeds/ # Static lookup data├── snapshots/ # SCD Type 2├── macros/ # Reusable SQL└── tests/ # Custom tests
dbt_project.yml
yaml
name: 'my_project'version: '1.0.0'config-version: 2profile: 'my_project'model-paths: ["models"]seed-paths: ["seeds"]test-paths: ["tests"]macro-paths: ["macros"]snapshot-paths: ["snapshots"]models:my_project:staging:+materialized: view+schema: stagingintermediate:+materialized: ephemeralmarts:+materialized: table+schema: marts
Staging Models
sql
-- models/staging/stg_orders.sql-- Naming: stg_<source>_<entity>with source as (select * from {{ source('raw', 'orders') }}),renamed as (select-- Rename to consistent namingid as order_id,customer_id,order_date,total_amount as order_total,-- Type castingcast(status as varchar(50)) as order_status,-- Timestampscreated_at,updated_atfrom source)select * from renamed
Source Definition
yaml
# models/staging/_sources.ymlversion: 2sources:- name: rawdatabase: raw_dbschema: publicfreshness:warn_after: {count: 12, period: hour}error_after: {count: 24, period: hour}tables:- name: ordersidentifier: orders_tablecolumns:- name: idtests:- unique- not_null- name: customers
Intermediate Models
sql
-- models/intermediate/int_orders_enriched.sql-- Join staging models, apply business logicwith orders as (select * from {{ ref('stg_orders') }}),customers as (select * from {{ ref('stg_customers') }}),products as (select * from {{ ref('stg_products') }})selecto.order_id,o.order_date,o.order_total,c.customer_id,c.customer_name,c.customer_segment,-- Business logiccasewhen o.order_total >= 1000 then 'high_value'when o.order_total >= 100 then 'medium_value'else 'low_value'end as order_tierfrom orders oleft join customers c on o.customer_id = c.customer_id
Mart Models
sql
-- models/marts/finance/fct_revenue.sql-- Final aggregated fact table{{ config(materialized='table',partition_by={"field": "order_date","data_type": "date","granularity": "month"}) }}with orders as (select * from {{ ref('int_orders_enriched') }})selectdate_trunc('day', order_date) as revenue_date,customer_segment,order_tier,count(*) as order_count,sum(order_total) as total_revenue,avg(order_total) as avg_order_valuefrom ordersgroup by 1, 2, 3
Incremental Models
sql
-- models/marts/fct_events.sql{{ config(materialized='incremental',unique_key='event_id',incremental_strategy='merge' -- or 'delete+insert', 'append') }}selectevent_id,user_id,event_type,event_timestamp,propertiesfrom {{ source('raw', 'events') }}{% if is_incremental() %}-- Only new/updated rows since last runwhere event_timestamp > (select max(event_timestamp) from {{ this }}){% endif %}
Snapshots (SCD Type 2)
sql
-- snapshots/snap_customers.sql{% snapshot snap_customers %}{{config(target_schema='snapshots',unique_key='customer_id',strategy='timestamp',updated_at='updated_at',)}}select * from {{ source('raw', 'customers') }}{% endsnapshot %}
Tests
yaml
# models/marts/_schema.ymlversion: 2models:- name: fct_revenuedescription: Daily revenue aggregationscolumns:- name: revenue_datetests:- not_null- name: total_revenuetests:- not_null- dbt_utils.accepted_range:min_value: 0tests:# Model-level tests- dbt_utils.unique_combination_of_columns:combination_of_columns:- revenue_date- customer_segment- order_tier
Custom Tests
sql
-- tests/assert_positive_revenue.sql-- Returns rows that fail the testselectrevenue_date,total_revenuefrom {{ ref('fct_revenue') }}where total_revenue < 0
Macros
sql
-- macros/cents_to_dollars.sql{% macro cents_to_dollars(column_name) %}round({{ column_name }} / 100.0, 2){% endmacro %}-- Usage in model:-- select {{ cents_to_dollars('amount_cents') }} as amount_dollars
sql
-- macros/generate_schema_name.sql{% macro generate_schema_name(custom_schema_name, node) %}{% if custom_schema_name %}{{ custom_schema_name }}{% else %}{{ target.schema }}{% endif %}{% endmacro %}
dbt Commands
bash
# Run all modelsdbt run# Run specific model and dependenciesdbt run --select fct_revenue+# Run models with tagdbt run --select tag:finance# Test alldbt test# Generate docsdbt docs generatedbt docs serve# Freshness checkdbt source freshness# Full refresh of incrementaldbt run --full-refresh --select fct_events# Build (run + test)dbt build
Best Practices
yaml
# 1. Use ref() for model references# BAD: select * from schema.stg_orders# GOOD: select * from {{ ref('stg_orders') }}# 2. Use source() for raw tables# BAD: select * from raw_db.orders# GOOD: select * from {{ source('raw', 'orders') }}# 3. Document modelsmodels:- name: fct_revenuedescription: |Daily revenue by segment. Grain: one row per day/segment/tier.Updated daily by the finance_dag.meta:owner: data-teampii: false
Packages
yaml
# packages.ymlpackages:- package: dbt-labs/dbt_utilsversion: 1.1.1- package: dbt-labs/codegenversion: 0.12.1- package: calogica/dbt_expectationsversion: 0.10.1
bash
# Install packagesdbt deps