[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6HR5FD10Q1CZ570FYGXRTRB":3,"skill-same:01M6HR5FD10Q1CZ570FYGXRTRB":75},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":27,"publishedAt":49,"linkOnly":50,"markdownContent":51,"markdownBody":52,"frontMatter":53,"refName":54,"commitSha":55,"skillDirectory":56,"forksCount":57,"repositoryHtmlUrl":58,"repositoryHomepageUrl":6,"ownerHtmlUrl":59,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":60,"install":61,"resources":74},"01M6HR5FD10Q1CZ570FYGXRTRB","dbt-transformation-patterns",null,"Master dbt (data build tool) for analytics engineering with model organization, testing, documentation, and incremental strategies. Use when building data transformations, creating data models, or implementing analytics engineering best practices.","welflau\u002Fai-dev-system","welflau","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F7010385?v=4","01M6HPTDGF18RFY07M229P8CTM","01M6HPTDMRMZCJPYBFEA9XVVYT",3,"MIT","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fexternal_plugins\u002Fdata-engineering\u002Fskills\u002Fdbt-transformation-patterns\u002FSKILL.md",[17,22],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000008","测试与质量","SCENARIO","使用场景",{"categoryNo":23,"categoryName":24,"taxonomyType":25,"taxonomyTypeDesc":26},"01JBSEEDCAT000000000000033","数据分析师","PROFESSION","适用职业",[28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48],"dbt","transformation","dbt transformation patterns","patterns","when","testing","for","implementing","with","with model","strategies","organization","analytics engineering","build","models","use","model","tool","data","best practices","documentation","2026-11-10 10:12:30",false,"---\nname: dbt-transformation-patterns\ndescription: Master dbt (data build tool) for analytics engineering with model organization, testing, documentation, and incremental strategies. Use when building data transformations, creating data models, or implementing analytics engineering best practices.\n---\n\n# dbt Transformation Patterns\n\nProduction-ready patterns for dbt (data build tool) including model organization, testing strategies, documentation, and incremental processing.\n\n## When to Use This Skill\n\n- Building data transformation pipelines with dbt\n- Organizing models into staging, intermediate, and marts layers\n- Implementing data quality tests\n- Creating incremental models for large datasets\n- Documenting data models and lineage\n- Setting up dbt project structure\n\n## Core Concepts\n\n### 1. Model Layers (Medallion Architecture)\n\n```\nsources\u002F          Raw data definitions\n    ↓\nstaging\u002F          1:1 with source, light cleaning\n    ↓\nintermediate\u002F     Business logic, joins, aggregations\n    ↓\nmarts\u002F            Final analytics tables\n```\n\n### 2. Naming Conventions\n\n| Layer | Prefix | Example |\n|-------|--------|---------|\n| Staging | `stg_` | `stg_stripe__payments` |\n| Intermediate | `int_` | `int_payments_pivoted` |\n| Marts | `dim_`, `fct_` | `dim_customers`, `fct_orders` |\n\n## Quick Start\n\n```yaml\n# dbt_project.yml\nname: 'analytics'\nversion: '1.0.0'\nprofile: 'analytics'\n\nmodel-paths: [\"models\"]\nanalysis-paths: [\"analyses\"]\ntest-paths: [\"tests\"]\nseed-paths: [\"seeds\"]\nmacro-paths: [\"macros\"]\n\nvars:\n  start_date: '2020-01-01'\n\nmodels:\n  analytics:\n    staging:\n      +materialized: view\n      +schema: staging\n    intermediate:\n      +materialized: ephemeral\n    marts:\n      +materialized: table\n      +schema: analytics\n```\n\n```\n# Project structure\nmodels\u002F\n├── staging\u002F\n│   ├── stripe\u002F\n│   │   ├── _stripe__sources.yml\n│   │   ├── _stripe__models.yml\n│   │   ├── stg_stripe__customers.sql\n│   │   └── stg_stripe__payments.sql\n│   └── shopify\u002F\n│       ├── _shopify__sources.yml\n│       └── stg_shopify__orders.sql\n├── intermediate\u002F\n│   └── finance\u002F\n│       └── int_payments_pivoted.sql\n└── marts\u002F\n    ├── core\u002F\n    │   ├── _core__models.yml\n    │   ├── dim_customers.sql\n    │   └── fct_orders.sql\n    └── finance\u002F\n        └── fct_revenue.sql\n```\n\n## Patterns\n\n### Pattern 1: Source Definitions\n\n```yaml\n# models\u002Fstaging\u002Fstripe\u002F_stripe__sources.yml\nversion: 2\n\nsources:\n  - name: stripe\n    description: Raw Stripe data loaded via Fivetran\n    database: raw\n    schema: stripe\n    loader: fivetran\n    loaded_at_field: _fivetran_synced\n    freshness:\n      warn_after: {count: 12, period: hour}\n      error_after: {count: 24, period: hour}\n    tables:\n      - name: customers\n        description: Stripe customer records\n        columns:\n          - name: id\n            description: Primary key\n            tests:\n              - unique\n              - not_null\n          - name: email\n            description: Customer email\n          - name: created\n            description: Account creation timestamp\n\n      - name: payments\n        description: Stripe payment transactions\n        columns:\n          - name: id\n            tests:\n              - unique\n              - not_null\n          - name: customer_id\n            tests:\n              - not_null\n              - relationships:\n                  to: source('stripe', 'customers')\n                  field: id\n```\n\n### Pattern 2: Staging Models\n\n```sql\n-- models\u002Fstaging\u002Fstripe\u002Fstg_stripe__customers.sql\nwith source as (\n    select * from {{ source('stripe', 'customers') }}\n),\n\nrenamed as (\n    select\n        -- ids\n        id as customer_id,\n\n        -- strings\n        lower(email) as email,\n        name as customer_name,\n\n        -- timestamps\n        created as created_at,\n\n        -- metadata\n        _fivetran_synced as _loaded_at\n\n    from source\n)\n\nselect * from renamed\n```\n\n```sql\n-- models\u002Fstaging\u002Fstripe\u002Fstg_stripe__payments.sql\n{{\n    config(\n        materialized='incremental',\n        unique_key='payment_id',\n        on_schema_change='append_new_columns'\n    )\n}}\n\nwith source as (\n    select * from {{ source('stripe', 'payments') }}\n\n    {% if is_incremental() %}\n    where _fivetran_synced > (select max(_loaded_at) from {{ this }})\n    {% endif %}\n),\n\nrenamed as (\n    select\n        -- ids\n        id as payment_id,\n        customer_id,\n        invoice_id,\n\n        -- amounts (convert cents to dollars)\n        amount \u002F 100.0 as amount,\n        amount_refunded \u002F 100.0 as amount_refunded,\n\n        -- status\n        status as payment_status,\n\n        -- timestamps\n        created as created_at,\n\n        -- metadata\n        _fivetran_synced as _loaded_at\n\n    from source\n)\n\nselect * from renamed\n```\n\n### Pattern 3: Intermediate Models\n\n```sql\n-- models\u002Fintermediate\u002Ffinance\u002Fint_payments_pivoted_to_customer.sql\nwith payments as (\n    select * from {{ ref('stg_stripe__payments') }}\n),\n\ncustomers as (\n    select * from {{ ref('stg_stripe__customers') }}\n),\n\npayment_summary as (\n    select\n        customer_id,\n        count(*) as total_payments,\n        count(case when payment_status = 'succeeded' then 1 end) as successful_payments,\n        sum(case when payment_status = 'succeeded' then amount else 0 end) as total_amount_paid,\n        min(created_at) as first_payment_at,\n        max(created_at) as last_payment_at\n    from payments\n    group by customer_id\n)\n\nselect\n    customers.customer_id,\n    customers.email,\n    customers.created_at as customer_created_at,\n    coalesce(payment_summary.total_payments, 0) as total_payments,\n    coalesce(payment_summary.successful_payments, 0) as successful_payments,\n    coalesce(payment_summary.total_amount_paid, 0) as lifetime_value,\n    payment_summary.first_payment_at,\n    payment_summary.last_payment_at\n\nfrom customers\nleft join payment_summary using (customer_id)\n```\n\n### Pattern 4: Mart Models (Dimensions and Facts)\n\n```sql\n-- models\u002Fmarts\u002Fcore\u002Fdim_customers.sql\n{{\n    config(\n        materialized='table',\n        unique_key='customer_id'\n    )\n}}\n\nwith customers as (\n    select * from {{ ref('int_payments_pivoted_to_customer') }}\n),\n\norders as (\n    select * from {{ ref('stg_shopify__orders') }}\n),\n\norder_summary as (\n    select\n        customer_id,\n        count(*) as total_orders,\n        sum(total_price) as total_order_value,\n        min(created_at) as first_order_at,\n        max(created_at) as last_order_at\n    from orders\n    group by customer_id\n),\n\nfinal as (\n    select\n        -- surrogate key\n        {{ dbt_utils.generate_surrogate_key(['customers.customer_id']) }} as customer_key,\n\n        -- natural key\n        customers.customer_id,\n\n        -- attributes\n        customers.email,\n        customers.customer_created_at,\n\n        -- payment metrics\n        customers.total_payments,\n        customers.successful_payments,\n        customers.lifetime_value,\n        customers.first_payment_at,\n        customers.last_payment_at,\n\n        -- order metrics\n        coalesce(order_summary.total_orders, 0) as total_orders,\n        coalesce(order_summary.total_order_value, 0) as total_order_value,\n        order_summary.first_order_at,\n        order_summary.last_order_at,\n\n        -- calculated fields\n        case\n            when customers.lifetime_value >= 1000 then 'high'\n            when customers.lifetime_value >= 100 then 'medium'\n            else 'low'\n        end as customer_tier,\n\n        -- timestamps\n        current_timestamp as _loaded_at\n\n    from customers\n    left join order_summary using (customer_id)\n)\n\nselect * from final\n```\n\n```sql\n-- models\u002Fmarts\u002Fcore\u002Ffct_orders.sql\n{{\n    config(\n        materialized='incremental',\n        unique_key='order_id',\n        incremental_strategy='merge'\n    )\n}}\n\nwith orders as (\n    select * from {{ ref('stg_shopify__orders') }}\n\n    {% if is_incremental() %}\n    where updated_at > (select max(updated_at) from {{ this }})\n    {% endif %}\n),\n\ncustomers as (\n    select * from {{ ref('dim_customers') }}\n),\n\nfinal as (\n    select\n        -- keys\n        orders.order_id,\n        customers.customer_key,\n        orders.customer_id,\n\n        -- dimensions\n        orders.order_status,\n        orders.fulfillment_status,\n        orders.payment_status,\n\n        -- measures\n        orders.subtotal,\n        orders.tax,\n        orders.shipping,\n        orders.total_price,\n        orders.total_discount,\n        orders.item_count,\n\n        -- timestamps\n        orders.created_at,\n        orders.updated_at,\n        orders.fulfilled_at,\n\n        -- metadata\n        current_timestamp as _loaded_at\n\n    from orders\n    left join customers on orders.customer_id = customers.customer_id\n)\n\nselect * from final\n```\n\n### Pattern 5: Testing and Documentation\n\n```yaml\n# models\u002Fmarts\u002Fcore\u002F_core__models.yml\nversion: 2\n\nmodels:\n  - name: dim_customers\n    description: Customer dimension with payment and order metrics\n    columns:\n      - name: customer_key\n        description: Surrogate key for the customer dimension\n        tests:\n          - unique\n          - not_null\n\n      - name: customer_id\n        description: Natural key from source system\n        tests:\n          - unique\n          - not_null\n\n      - name: email\n        description: Customer email address\n        tests:\n          - not_null\n\n      - name: customer_tier\n        description: Customer value tier based on lifetime value\n        tests:\n          - accepted_values:\n              values: ['high', 'medium', 'low']\n\n      - name: lifetime_value\n        description: Total amount paid by customer\n        tests:\n          - dbt_utils.expression_is_true:\n              expression: \">= 0\"\n\n  - name: fct_orders\n    description: Order fact table with all order transactions\n    tests:\n      - dbt_utils.recency:\n          datepart: day\n          field: created_at\n          interval: 1\n    columns:\n      - name: order_id\n        tests:\n          - unique\n          - not_null\n      - name: customer_key\n        tests:\n          - not_null\n          - relationships:\n              to: ref('dim_customers')\n              field: customer_key\n```\n\n### Pattern 6: Macros and DRY Code\n\n```sql\n-- macros\u002Fcents_to_dollars.sql\n{% macro cents_to_dollars(column_name, precision=2) %}\n    round({{ column_name }} \u002F 100.0, {{ precision }})\n{% endmacro %}\n\n-- macros\u002Fgenerate_schema_name.sql\n{% macro generate_schema_name(custom_schema_name, node) %}\n    {%- set default_schema = target.schema -%}\n    {%- if custom_schema_name is none -%}\n        {{ default_schema }}\n    {%- else -%}\n        {{ default_schema }}_{{ custom_schema_name }}\n    {%- endif -%}\n{% endmacro %}\n\n-- macros\u002Flimit_data_in_dev.sql\n{% macro limit_data_in_dev(column_name, days=3) %}\n    {% if target.name == 'dev' %}\n        where {{ column_name }} >= dateadd(day, -{{ days }}, current_date)\n    {% endif %}\n{% endmacro %}\n\n-- Usage in model\nselect * from {{ ref('stg_orders') }}\n{{ limit_data_in_dev('created_at') }}\n```\n\n### Pattern 7: Incremental Strategies\n\n```sql\n-- Delete+Insert (default for most warehouses)\n{{\n    config(\n        materialized='incremental',\n        unique_key='id',\n        incremental_strategy='delete+insert'\n    )\n}}\n\n-- Merge (best for late-arriving data)\n{{\n    config(\n        materialized='incremental',\n        unique_key='id',\n        incremental_strategy='merge',\n        merge_update_columns=['status', 'amount', 'updated_at']\n    )\n}}\n\n-- Insert Overwrite (partition-based)\n{{\n    config(\n        materialized='incremental',\n        incremental_strategy='insert_overwrite',\n        partition_by={\n            \"field\": \"created_date\",\n            \"data_type\": \"date\",\n            \"granularity\": \"day\"\n        }\n    )\n}}\n\nselect\n    *,\n    date(created_at) as created_date\nfrom {{ ref('stg_events') }}\n\n{% if is_incremental() %}\nwhere created_date >= dateadd(day, -3, current_date)\n{% endif %}\n```\n\n## dbt Commands\n\n```bash\n# Development\ndbt run                          # Run all models\ndbt run --select staging         # Run staging models only\ndbt run --select +fct_orders     # Run fct_orders and its upstream\ndbt run --select fct_orders+     # Run fct_orders and its downstream\ndbt run --full-refresh           # Rebuild incremental models\n\n# Testing\ndbt test                         # Run all tests\ndbt test --select stg_stripe     # Test specific models\ndbt build                        # Run + test in DAG order\n\n# Documentation\ndbt docs generate                # Generate docs\ndbt docs serve                   # Serve docs locally\n\n# Debugging\ndbt compile                      # Compile SQL without running\ndbt debug                        # Test connection\ndbt ls --select tag:critical     # List models by tag\n```\n\n## Best Practices\n\n### Do's\n- **Use staging layer** - Clean data once, use everywhere\n- **Test aggressively** - Not null, unique, relationships\n- **Document everything** - Column descriptions, model descriptions\n- **Use incremental** - For tables > 1M rows\n- **Version control** - dbt project in Git\n\n### Don'ts\n- **Don't skip staging** - Raw → mart is tech debt\n- **Don't hardcode dates** - Use `{{ var('start_date') }}`\n- **Don't repeat logic** - Extract to macros\n- **Don't test in prod** - Use dev target\n- **Don't ignore freshness** - Monitor source data\n\n## Resources\n\n- [dbt Documentation](https:\u002F\u002Fdocs.getdbt.com\u002F)\n- [dbt Best Practices](https:\u002F\u002Fdocs.getdbt.com\u002Fguides\u002Fbest-practices)\n- [dbt-utils Package](https:\u002F\u002Fhub.getdbt.com\u002Fdbt-labs\u002Fdbt_utils\u002Flatest\u002F)\n- [dbt Discourse](https:\u002F\u002Fdiscourse.getdbt.com\u002F)\n","# dbt Transformation Patterns\n\nProduction-ready patterns for dbt (data build tool) including model organization, testing strategies, documentation, and incremental processing.\n\n## When to Use This Skill\n\n- Building data transformation pipelines with dbt\n- Organizing models into staging, intermediate, and marts layers\n- Implementing data quality tests\n- Creating incremental models for large datasets\n- Documenting data models and lineage\n- Setting up dbt project structure\n\n## Core Concepts\n\n### 1. Model Layers (Medallion Architecture)\n\n```\nsources\u002F          Raw data definitions\n    ↓\nstaging\u002F          1:1 with source, light cleaning\n    ↓\nintermediate\u002F     Business logic, joins, aggregations\n    ↓\nmarts\u002F            Final analytics tables\n```\n\n### 2. Naming Conventions\n\n| Layer | Prefix | Example |\n|-------|--------|---------|\n| Staging | `stg_` | `stg_stripe__payments` |\n| Intermediate | `int_` | `int_payments_pivoted` |\n| Marts | `dim_`, `fct_` | `dim_customers`, `fct_orders` |\n\n## Quick Start\n\n```yaml\n# dbt_project.yml\nname: 'analytics'\nversion: '1.0.0'\nprofile: 'analytics'\n\nmodel-paths: [\"models\"]\nanalysis-paths: [\"analyses\"]\ntest-paths: [\"tests\"]\nseed-paths: [\"seeds\"]\nmacro-paths: [\"macros\"]\n\nvars:\n  start_date: '2020-01-01'\n\nmodels:\n  analytics:\n    staging:\n      +materialized: view\n      +schema: staging\n    intermediate:\n      +materialized: ephemeral\n    marts:\n      +materialized: table\n      +schema: analytics\n```\n\n```\n# Project structure\nmodels\u002F\n├── staging\u002F\n│   ├── stripe\u002F\n│   │   ├── _stripe__sources.yml\n│   │   ├── _stripe__models.yml\n│   │   ├── stg_stripe__customers.sql\n│   │   └── stg_stripe__payments.sql\n│   └── shopify\u002F\n│       ├── _shopify__sources.yml\n│       └── stg_shopify__orders.sql\n├── intermediate\u002F\n│   └── finance\u002F\n│       └── int_payments_pivoted.sql\n└── marts\u002F\n    ├── core\u002F\n    │   ├── _core__models.yml\n    │   ├── dim_customers.sql\n    │   └── fct_orders.sql\n    └── finance\u002F\n        └── fct_revenue.sql\n```\n\n## Patterns\n\n### Pattern 1: Source Definitions\n\n```yaml\n# models\u002Fstaging\u002Fstripe\u002F_stripe__sources.yml\nversion: 2\n\nsources:\n  - name: stripe\n    description: Raw Stripe data loaded via Fivetran\n    database: raw\n    schema: stripe\n    loader: fivetran\n    loaded_at_field: _fivetran_synced\n    freshness:\n      warn_after: {count: 12, period: hour}\n      error_after: {count: 24, period: hour}\n    tables:\n      - name: customers\n        description: Stripe customer records\n        columns:\n          - name: id\n            description: Primary key\n            tests:\n              - unique\n              - not_null\n          - name: email\n            description: Customer email\n          - name: created\n            description: Account creation timestamp\n\n      - name: payments\n        description: Stripe payment transactions\n        columns:\n          - name: id\n            tests:\n              - unique\n              - not_null\n          - name: customer_id\n            tests:\n              - not_null\n              - relationships:\n                  to: source('stripe', 'customers')\n                  field: id\n```\n\n### Pattern 2: Staging Models\n\n```sql\n-- models\u002Fstaging\u002Fstripe\u002Fstg_stripe__customers.sql\nwith source as (\n    select * from {{ source('stripe', 'customers') }}\n),\n\nrenamed as (\n    select\n        -- ids\n        id as customer_id,\n\n        -- strings\n        lower(email) as email,\n        name as customer_name,\n\n        -- timestamps\n        created as created_at,\n\n        -- metadata\n        _fivetran_synced as _loaded_at\n\n    from source\n)\n\nselect * from renamed\n```\n\n```sql\n-- models\u002Fstaging\u002Fstripe\u002Fstg_stripe__payments.sql\n{{\n    config(\n        materialized='incremental',\n        unique_key='payment_id',\n        on_schema_change='append_new_columns'\n    )\n}}\n\nwith source as (\n    select * from {{ source('stripe', 'payments') }}\n\n    {% if is_incremental() %}\n    where _fivetran_synced > (select max(_loaded_at) from {{ this }})\n    {% endif %}\n),\n\nrenamed as (\n    select\n        -- ids\n        id as payment_id,\n        customer_id,\n        invoice_id,\n\n        -- amounts (convert cents to dollars)\n        amount \u002F 100.0 as amount,\n        amount_refunded \u002F 100.0 as amount_refunded,\n\n        -- status\n        status as payment_status,\n\n        -- timestamps\n        created as created_at,\n\n        -- metadata\n        _fivetran_synced as _loaded_at\n\n    from source\n)\n\nselect * from renamed\n```\n\n### Pattern 3: Intermediate Models\n\n```sql\n-- models\u002Fintermediate\u002Ffinance\u002Fint_payments_pivoted_to_customer.sql\nwith payments as (\n    select * from {{ ref('stg_stripe__payments') }}\n),\n\ncustomers as (\n    select * from {{ ref('stg_stripe__customers') }}\n),\n\npayment_summary as (\n    select\n        customer_id,\n        count(*) as total_payments,\n        count(case when payment_status = 'succeeded' then 1 end) as successful_payments,\n        sum(case when payment_status = 'succeeded' then amount else 0 end) as total_amount_paid,\n        min(created_at) as first_payment_at,\n        max(created_at) as last_payment_at\n    from payments\n    group by customer_id\n)\n\nselect\n    customers.customer_id,\n    customers.email,\n    customers.created_at as customer_created_at,\n    coalesce(payment_summary.total_payments, 0) as total_payments,\n    coalesce(payment_summary.successful_payments, 0) as successful_payments,\n    coalesce(payment_summary.total_amount_paid, 0) as lifetime_value,\n    payment_summary.first_payment_at,\n    payment_summary.last_payment_at\n\nfrom customers\nleft join payment_summary using (customer_id)\n```\n\n### Pattern 4: Mart Models (Dimensions and Facts)\n\n```sql\n-- models\u002Fmarts\u002Fcore\u002Fdim_customers.sql\n{{\n    config(\n        materialized='table',\n        unique_key='customer_id'\n    )\n}}\n\nwith customers as (\n    select * from {{ ref('int_payments_pivoted_to_customer') }}\n),\n\norders as (\n    select * from {{ ref('stg_shopify__orders') }}\n),\n\norder_summary as (\n    select\n        customer_id,\n        count(*) as total_orders,\n        sum(total_price) as total_order_value,\n        min(created_at) as first_order_at,\n        max(created_at) as last_order_at\n    from orders\n    group by customer_id\n),\n\nfinal as (\n    select\n        -- surrogate key\n        {{ dbt_utils.generate_surrogate_key(['customers.customer_id']) }} as customer_key,\n\n        -- natural key\n        customers.customer_id,\n\n        -- attributes\n        customers.email,\n        customers.customer_created_at,\n\n        -- payment metrics\n        customers.total_payments,\n        customers.successful_payments,\n        customers.lifetime_value,\n        customers.first_payment_at,\n        customers.last_payment_at,\n\n        -- order metrics\n        coalesce(order_summary.total_orders, 0) as total_orders,\n        coalesce(order_summary.total_order_value, 0) as total_order_value,\n        order_summary.first_order_at,\n        order_summary.last_order_at,\n\n        -- calculated fields\n        case\n            when customers.lifetime_value >= 1000 then 'high'\n            when customers.lifetime_value >= 100 then 'medium'\n            else 'low'\n        end as customer_tier,\n\n        -- timestamps\n        current_timestamp as _loaded_at\n\n    from customers\n    left join order_summary using (customer_id)\n)\n\nselect * from final\n```\n\n```sql\n-- models\u002Fmarts\u002Fcore\u002Ffct_orders.sql\n{{\n    config(\n        materialized='incremental',\n        unique_key='order_id',\n        incremental_strategy='merge'\n    )\n}}\n\nwith orders as (\n    select * from {{ ref('stg_shopify__orders') }}\n\n    {% if is_incremental() %}\n    where updated_at > (select max(updated_at) from {{ this }})\n    {% endif %}\n),\n\ncustomers as (\n    select * from {{ ref('dim_customers') }}\n),\n\nfinal as (\n    select\n        -- keys\n        orders.order_id,\n        customers.customer_key,\n        orders.customer_id,\n\n        -- dimensions\n        orders.order_status,\n        orders.fulfillment_status,\n        orders.payment_status,\n\n        -- measures\n        orders.subtotal,\n        orders.tax,\n        orders.shipping,\n        orders.total_price,\n        orders.total_discount,\n        orders.item_count,\n\n        -- timestamps\n        orders.created_at,\n        orders.updated_at,\n        orders.fulfilled_at,\n\n        -- metadata\n        current_timestamp as _loaded_at\n\n    from orders\n    left join customers on orders.customer_id = customers.customer_id\n)\n\nselect * from final\n```\n\n### Pattern 5: Testing and Documentation\n\n```yaml\n# models\u002Fmarts\u002Fcore\u002F_core__models.yml\nversion: 2\n\nmodels:\n  - name: dim_customers\n    description: Customer dimension with payment and order metrics\n    columns:\n      - name: customer_key\n        description: Surrogate key for the customer dimension\n        tests:\n          - unique\n          - not_null\n\n      - name: customer_id\n        description: Natural key from source system\n        tests:\n          - unique\n          - not_null\n\n      - name: email\n        description: Customer email address\n        tests:\n          - not_null\n\n      - name: customer_tier\n        description: Customer value tier based on lifetime value\n        tests:\n          - accepted_values:\n              values: ['high', 'medium', 'low']\n\n      - name: lifetime_value\n        description: Total amount paid by customer\n        tests:\n          - dbt_utils.expression_is_true:\n              expression: \">= 0\"\n\n  - name: fct_orders\n    description: Order fact table with all order transactions\n    tests:\n      - dbt_utils.recency:\n          datepart: day\n          field: created_at\n          interval: 1\n    columns:\n      - name: order_id\n        tests:\n          - unique\n          - not_null\n      - name: customer_key\n        tests:\n          - not_null\n          - relationships:\n              to: ref('dim_customers')\n              field: customer_key\n```\n\n### Pattern 6: Macros and DRY Code\n\n```sql\n-- macros\u002Fcents_to_dollars.sql\n{% macro cents_to_dollars(column_name, precision=2) %}\n    round({{ column_name }} \u002F 100.0, {{ precision }})\n{% endmacro %}\n\n-- macros\u002Fgenerate_schema_name.sql\n{% macro generate_schema_name(custom_schema_name, node) %}\n    {%- set default_schema = target.schema -%}\n    {%- if custom_schema_name is none -%}\n        {{ default_schema }}\n    {%- else -%}\n        {{ default_schema }}_{{ custom_schema_name }}\n    {%- endif -%}\n{% endmacro %}\n\n-- macros\u002Flimit_data_in_dev.sql\n{% macro limit_data_in_dev(column_name, days=3) %}\n    {% if target.name == 'dev' %}\n        where {{ column_name }} >= dateadd(day, -{{ days }}, current_date)\n    {% endif %}\n{% endmacro %}\n\n-- Usage in model\nselect * from {{ ref('stg_orders') }}\n{{ limit_data_in_dev('created_at') }}\n```\n\n### Pattern 7: Incremental Strategies\n\n```sql\n-- Delete+Insert (default for most warehouses)\n{{\n    config(\n        materialized='incremental',\n        unique_key='id',\n        incremental_strategy='delete+insert'\n    )\n}}\n\n-- Merge (best for late-arriving data)\n{{\n    config(\n        materialized='incremental',\n        unique_key='id',\n        incremental_strategy='merge',\n        merge_update_columns=['status', 'amount', 'updated_at']\n    )\n}}\n\n-- Insert Overwrite (partition-based)\n{{\n    config(\n        materialized='incremental',\n        incremental_strategy='insert_overwrite',\n        partition_by={\n            \"field\": \"created_date\",\n            \"data_type\": \"date\",\n            \"granularity\": \"day\"\n        }\n    )\n}}\n\nselect\n    *,\n    date(created_at) as created_date\nfrom {{ ref('stg_events') }}\n\n{% if is_incremental() %}\nwhere created_date >= dateadd(day, -3, current_date)\n{% endif %}\n```\n\n## dbt Commands\n\n```bash\n# Development\ndbt run                          # Run all models\ndbt run --select staging         # Run staging models only\ndbt run --select +fct_orders     # Run fct_orders and its upstream\ndbt run --select fct_orders+     # Run fct_orders and its downstream\ndbt run --full-refresh           # Rebuild incremental models\n\n# Testing\ndbt test                         # Run all tests\ndbt test --select stg_stripe     # Test specific models\ndbt build                        # Run + test in DAG order\n\n# Documentation\ndbt docs generate                # Generate docs\ndbt docs serve                   # Serve docs locally\n\n# Debugging\ndbt compile                      # Compile SQL without running\ndbt debug                        # Test connection\ndbt ls --select tag:critical     # List models by tag\n```\n\n## Best Practices\n\n### Do's\n- **Use staging layer** - Clean data once, use everywhere\n- **Test aggressively** - Not null, unique, relationships\n- **Document everything** - Column descriptions, model descriptions\n- **Use incremental** - For tables > 1M rows\n- **Version control** - dbt project in Git\n\n### Don'ts\n- **Don't skip staging** - Raw → mart is tech debt\n- **Don't hardcode dates** - Use `{{ var('start_date') }}`\n- **Don't repeat logic** - Extract to macros\n- **Don't test in prod** - Use dev target\n- **Don't ignore freshness** - Monitor source data\n\n## Resources\n\n- [dbt Documentation](https:\u002F\u002Fdocs.getdbt.com\u002F)\n- [dbt Best Practices](https:\u002F\u002Fdocs.getdbt.com\u002Fguides\u002Fbest-practices)\n- [dbt-utils Package](https:\u002F\u002Fhub.getdbt.com\u002Fdbt-labs\u002Fdbt_utils\u002Flatest\u002F)\n- [dbt Discourse](https:\u002F\u002Fdiscourse.getdbt.com\u002F)\n",{"name":5,"description":7},"main","18d0e63d1313ca87098f614aa7c1e2dcf6de79c7","backend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fexternal_plugins\u002Fdata-engineering\u002Fskills\u002Fdbt-transformation-patterns",1,"https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system","https:\u002F\u002Fgithub.com\u002Fwelflau","2026-11-12 14:55:20",{"source":8,"skillName":5,"commands":62,"prompt":72,"zipAvailable":73},[63,66,69],{"tool":64,"command":65},"npx","npx skills add welflau\u002Fai-dev-system --skill dbt-transformation-patterns",{"tool":67,"command":68},"bunx","bunx skills add welflau\u002Fai-dev-system --skill dbt-transformation-patterns",{"tool":70,"command":71},"pnpm","pnpm dlx skills add welflau\u002Fai-dev-system --skill dbt-transformation-patterns","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fexternal_plugins\u002Fdata-engineering\u002Fskills\u002Fdbt-transformation-patterns\u002FSKILL.md",true,[],[76,104,133,159,186,211],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":80,"licenseFileUrl":81,"sourceHtmlUrl":82,"categories":83,"keywords":88,"publishedAt":103},"01M6HS9Z4B0YA8CJCS2Y2F04Y3","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fexternal_plugins\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fexternal_plugins\u002Fwebapp-testing\u002FSKILL.md",[84,85],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},{"categoryNo":86,"categoryName":87,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000009","前端开发",[33,89,90,91,92,93,94,95,96,97,98,99,100,101,102,36,34],"webapp testing","webapp","frontend","screenshots","playwright","web","debugging","toolkit","browser","ui","logs","applications","behavior","local","2026-11-11 15:11:14",{"skillNo":105,"name":106,"nameZh":6,"description":107,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":80,"licenseFileUrl":108,"sourceHtmlUrl":109,"categories":110,"keywords":114,"publishedAt":103},"01M6HRAGMG7JF0HXYHMA5QHS8A","internal-comms","A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.).","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fexternal_plugins\u002Finternal-comms\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fexternal_plugins\u002Finternal-comms\u002FSKILL.md",[111],{"categoryNo":112,"categoryName":113,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000005","邮件与沟通",[115,116,117,118,119,120,43,121,122,123,124,125,126,127,128,129,130,131,132],"internal comms","comms","status","help","SET","write","reports","me","incident","leadership","project","resources","communications","internal communications","formats","sort","my","updates",{"skillNo":134,"name":135,"nameZh":6,"description":136,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":80,"licenseFileUrl":137,"sourceHtmlUrl":138,"categories":139,"keywords":141,"publishedAt":49},"01M6HSTDP4M3JFXEBK91VFB4PA","web-artifacts-builder","Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn\u002Fui). Use for complex artifacts requiring state management, routing, or shadcn\u002Fui components - not for simple single-file HTML\u002FJSX artifacts.","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fplugins\u002Fweb-artifacts-builder\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fplugins\u002Fweb-artifacts-builder\u002FSKILL.md",[140],{"categoryNo":86,"categoryName":87,"taxonomyType":20,"taxonomyTypeDesc":21},[142,94,143,144,145,91,146,147,148,149,150,151,152,153,43,154,155,156,157,34,158],"web artifacts builder","artifacts","artifacts builder","builder","css","components","react","routing","state management","state","file","Tailwind","single-file","simple","ui components","multi","single",{"skillNo":160,"name":161,"nameZh":6,"description":162,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":80,"licenseFileUrl":163,"sourceHtmlUrl":164,"categories":165,"keywords":173,"publishedAt":49},"01M6HSDXH0JSP8R3QTNY9XZ8HN","frontend-design","Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, artifacts, posters, or applications (examples include websites, landing pages, dashboards, React components, HTML\u002FCSS layouts, or when styling\u002Fbeautifying any web UI). Generates creative, polished code and UI design that avoids generic AI aesthetics.","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fplugins\u002Ffrontend-design\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fplugins\u002Ffrontend-design\u002FSKILL.md",[166,167,170],{"categoryNo":86,"categoryName":87,"taxonomyType":20,"taxonomyTypeDesc":21},{"categoryNo":168,"categoryName":169,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000015","视觉设计",{"categoryNo":171,"categoryName":172,"taxonomyType":25,"taxonomyTypeDesc":26},"01JBSEEDCAT000000000000032","设计师",[91,174,175,146,94,147,148,176,177,178,143,179,100,180,43,181,182,183,184,36,185,32],"design","frontend design","react components","create","code","examples","landing","ui design","pages","aesthetics","web ui","generic",{"skillNo":187,"name":188,"nameZh":6,"description":189,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":80,"licenseFileUrl":190,"sourceHtmlUrl":191,"categories":192,"keywords":194,"publishedAt":49},"01M6HSA77QYVP7A72HREGTDN2C","algorithmic-art","Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fplugins\u002Falgorithmic-art\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fplugins\u002Falgorithmic-art\u002FSKILL.md",[193],{"categoryNo":168,"categoryName":169,"taxonomyType":20,"taxonomyTypeDesc":21},[195,196,197,177,178,198,199,200,201,43,202,203,204,205,36,206,207,208,209,210,32],"algorithmic art","Art","algorithmic","flow","js","work","interactive","generative art","exploration","systems","users","Existing","request","generative","copyright","fields",{"skillNo":212,"name":213,"nameZh":6,"description":214,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":80,"licenseFileUrl":215,"sourceHtmlUrl":216,"categories":217,"keywords":219,"publishedAt":49},"01M6HS9HE0X390Y6RQKTY1YNGJ","theme-factory","Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors\u002Ffonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fexternal_plugins\u002Ftheme-factory\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fexternal_plugins\u002Ftheme-factory\u002FSKILL.md",[218],{"categoryNo":168,"categoryName":169,"taxonomyType":20,"taxonomyTypeDesc":21},[220,221,222,223,96,224,143,119,225,226,180,227,228,182,229,36,230,231,232,34,233,234],"theme factory","factory","theme","docs","generate","fly","slides","styling","artifact","themes","you","fonts","can","apply","new"]