[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M70JT848VGYH3XPRV6ZRK46D":3,"skill-same:01M70JT848VGYH3XPRV6ZRK46D":78},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":28,"publishedAt":49,"linkOnly":50,"markdownContent":51,"markdownBody":52,"frontMatter":53,"refName":54,"commitSha":55,"skillDirectory":56,"forksCount":57,"repositoryHtmlUrl":58,"repositoryHomepageUrl":59,"ownerHtmlUrl":60,"ownerBlogUrl":61,"ownerDescription":62,"updatedAt":63,"install":64,"resources":77},"01M70JT848VGYH3XPRV6ZRK46D","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.","shengdabai\u002FTony-Claude-Code-Skills","shengdabai","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F116417419?v=4","01M70F6D2WY5PQV5A92BKYJQEW","Tony Sheng","01M70F6D3GAAAYZ5H4CC1G8VXM",3,"MIT","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002F_collections\u002Fwshobson-agents\u002Fplugins\u002Fdata-engineering\u002Fskills\u002Fdbt-transformation-patterns\u002FSKILL.md",[18,23],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000008","测试与质量","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":26,"taxonomyTypeDesc":27},"01JBSEEDCAT000000000000033","数据分析师","PROFESSION","适用职业",[29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48],"transformation","dbt transformation patterns","dbt","patterns","with","best practices","analytics engineering","use","tool","for","analytics","master","data","organization","strategies","documentation","when","implementing","testing","model","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","7850740bd837adb32f0a109ab2af82482196c6f2","skills\u002F_collections\u002Fwshobson-agents\u002Fplugins\u002Fdata-engineering\u002Fskills\u002Fdbt-transformation-patterns",1,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills","https:\u002F\u002Fzturnsgo.com","https:\u002F\u002Fgithub.com\u002Fshengdabai","https:\u002F\u002Fzturnsgo.com\u002F","AI × education creator — producer, not consumer. Taught 6,000+ learners; shipping learning tools & daily essays with Claude Code, practicing @xiaolai's way 🥋","2026-11-01 21:28:23",{"source":8,"skillName":5,"commands":65,"prompt":75,"zipAvailable":76},[66,69,72],{"tool":67,"command":68},"npx","npx skills add shengdabai\u002FTony-Claude-Code-Skills --skill dbt-transformation-patterns",{"tool":70,"command":71},"bunx","bunx skills add shengdabai\u002FTony-Claude-Code-Skills --skill dbt-transformation-patterns",{"tool":73,"command":74},"pnpm","pnpm dlx skills add shengdabai\u002FTony-Claude-Code-Skills --skill dbt-transformation-patterns","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002F_collections\u002Fwshobson-agents\u002Fplugins\u002Fdata-engineering\u002Fskills\u002Fdbt-transformation-patterns\u002FSKILL.md",true,[],[79,88,96,104,112,120],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":83,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":87},"01M73H7XKBHE1ETQDZT94MF9HH","seedance-prompt-en","Write effective prompts for Jimeng Seedance 2.0 multimodal AI video generation. Use when users want to create video prompts using text, images, videos, and audio inputs with the @ reference system. Covers camera movements, effects replication, video extension, editing, music beat-matching, e-commerce ads, short dramas, and educational content.","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fseedance-prompt-en\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fseedance-prompt-en\u002FSKILL.md",[],[],"2026-11-11 15:11:14",{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":92,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":87},"01M73GRE9998Q1DZWC71N41JWG","onepage-pdf","Convert an HTML page into a single continuous-page PDF (one tall page, no pagination breaks), preserving desktop layout, backgrounds and selectable text. Use when the user asks to turn an HTML file\u002Freport\u002Fproposal into a \"single-page PDF\", \"long PDF\", \"不分页 PDF\", \"单页 PDF\", \"长图式 PDF\", or complains that an HTML-to-PDF export breaks into pages or cuts content. Supports optional string redaction with leak verification.","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fonepage-pdf\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fonepage-pdf\u002FSKILL.md",[],[],{"skillNo":97,"name":98,"nameZh":6,"description":99,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":100,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":87},"01M73GQG1KZDADVPV3MHAT1J5A","native-feel-cross-platform-desktop","Use when the user is designing, prototyping, or rewriting a desktop app that must run on multiple OSes (macOS + Windows, optionally Linux) AND feel indistinguishable from a native app to its users — fast launch, native windowing, native input handling, native materials. Trigger words include \"cross-platform desktop\", \"Electron alternative\", \"Tauri vs native\", \"WebView wrapper\", \"near-native performance\", \"Raycast architecture\", \"WebKit\u002FWebView2 quirks\", \"WKWebView\", \"system tray app\", \"global hotkey app\", \"launcher app\". Do NOT trigger this skill for pure web apps, pure mobile apps, or for greenfield projects that have no native-feel requirement.","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fnative-feel-cross-platform-desktop\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fnative-feel-cross-platform-desktop\u002FSKILL.md",[],[],{"skillNo":105,"name":106,"nameZh":6,"description":107,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":108,"sourceHtmlUrl":109,"categories":110,"keywords":111,"publishedAt":87},"01M73G87PDNSMKG2FHWCYER6N8","gstack","Router for the gstack skill suite. (gstack)","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fgstack\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fgstack\u002FSKILL.md",[],[],{"skillNo":113,"name":114,"nameZh":6,"description":115,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":116,"sourceHtmlUrl":117,"categories":118,"keywords":119,"publishedAt":87},"01M73G3EAQWKCM8DB8D0N0QSVG","fireworks-tech-graph","Use when the user wants to create any technical diagram - architecture, data flow, flowchart, sequence, agent\u002Fmemory, or concept map - and export as SVG+PNG. Trigger on: \"画图\" \"帮我画\" \"生成图\" \"做个图\" \"架构图\" \"流程图\" \"可视化一下\" \"出图\" \"generate diagram\" \"draw diagram\" \"visualize\" or any system\u002Fflow description the user wants illustrated.","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Ffireworks-tech-graph\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Ffireworks-tech-graph\u002FSKILL.md",[],[],{"skillNo":121,"name":122,"nameZh":6,"description":123,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":124,"categories":125,"keywords":126,"publishedAt":87},"01M73G086AXAH9DW1H5G5N3CPB","dbs-video-extract","接收抖音、小红书、微信视频号等短视频链接或分享文案，查询作品／账号数据并提取语音文字稿，按作者和标题归档为 Markdown。用户希望完整解析短视频、取得数据或文字稿时使用；运行前检查 TikHub 与轻抖使用凭证，缺少时用新手能理解的方式引导购买和安全配置。","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fdbs-video-extract\u002FSKILL.md",[],[]]