altimate-code
Delegates dbt and warehouse work to altimate-code, a specialized CLI agent with 100+ purpose-built data tools. USE THIS SKILL…
Safely refactors dbt models with downstream impact analysis. Use when restructuring dbt models for: (1) Task mentions "refactor", "restructure", "extract", "split", "break into", or "reorganize" (2) Extracting CTEs to intermediate models or creating macros (3) Modifying model
$ npx -y skills add AltimateAI/data-engineering-skills --skill refactoring-dbt-models --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/refactoring-dbt-modelsContext preview
The summary Claude sees to decide when to auto-load this skill.
Safely refactors dbt models with downstream impact analysis. Use when restructuring dbt models for: (1) Task mentions "refactor", "restructure", "extract", "split", "break into", or "reorganize" (2) Extracting CTEs to intermediate models or creating macros (3) Modifying model
name: refactoring-dbt-models description: | Safely refactors dbt models with downstream impact analysis. Use when restructuring dbt models for: (1) Task mentions "refactor", "restructure", "extract", "split", "break into", or "reorganize" (2) Extracting CTEs to intermediate models or creating macros (3) Modifying model logic that has downstream consumers (4) Renaming columns, changing types, or reorganizing model dependencies Analyzes all downstream dependencies BEFORE making changes.
**Find ALL downstream dependencies before changing. Refactor in small steps. Verify output after each change.**
cat models/<path>/<model_name>.sql
Identify refactoring opportunities:
**CRITICAL: Never refactor without knowing impact.**
# Get full dependency tree (model and all its children)
dbt ls --select model_name+ --output list
# Find all models referencing this one
grep -r "ref('model_name')" models/ --include="*.sql"**Report to user:** "Found X downstream models: [list]. These will be affected by changes."
**BEFORE changing any columns, check what downstream models reference:**
# For each downstream model, check what columns it uses cat models/<path>/<downstream_model>.sql | grep -E "model_name\.\w+|alias\.\w+"
If downstream models reference specific columns, you MUST ensure those columns remain available after refactoring.
| Opportunity | Strategy | |-------------|----------| | Long CTE | Extract to intermediate model | | Repeated logic | Create macro in `macros/` | | Complex join | Split into intermediate models | | Multiple concerns | Separate into focused models |
Before:
-- orders.sql (200 lines)
with customer_metrics as (
-- 50 lines of complex logic
),
order_enriched as (
select ...
from orders
join customer_metrics on ...
)
select * from order_enrichedAfter:
-- customer_metrics.sql (new file)
select
customer_id,
-- complex logic here
from {{ ref('customers') }}
-- orders.sql (simplified)
with order_enriched as (
select ...
from {{ ref('raw_orders') }} orders
join {{ ref('customer_metrics') }} cm on ...
)
select * from order_enrichedBefore (repeated in multiple models):
case
when amount < 0 then 'refund'
when amount = 0 then 'zero'
else 'positive'
end as amount_categoryAfter:
-- macros/categorize_amount.sql
{% macro categorize_amount(column_name) %}
case
when {{ column_name }} < 0 then 'refund'
when {{ column_name }} = 0 then 'zero'
else 'positive'
end
{% endmacro %}
-- In models:
{{ categorize_amount('amount') }} as amount_category# Compile to check syntax dbt compile --select +model_name+ # Build entire lineage dbt build --select +model_name+ # Check row counts (manual) # Before: Record expected counts # After: Verify counts match
**CRITICAL: Refactoring should not change output.**
# Compare row counts before and after
dbt show --inline "select count(*) from {{ ref('model_name') }}"
# Spot check key values
dbt show --select <model_name> --limit 10If changing output columns: 1. Update all downstream refs 2. Update schema.yml documentation 3. Re-run downstream tests
| Symptom | Refactoring | |---------|-------------| | Model > 200 lines | Extract CTEs to models | | Same logic in 3+ models | Extract to macro | | 5+ joins in one model | Create intermediate models | | Hard to understand | Add CTEs with clear names | | Slow performance | Split to allow parallelization |
Claude Code skills for Analytics & Data engineers working with dbt and Snowflake Altimate Data Skills is a collection of Claude Code skills that encode the workflows and best practices of experienced analytics engineers.
Delegates dbt and warehouse work to altimate-code, a specialized CLI agent with 100+ purpose-built data tools. USE THIS SKILL…
Analyze DBSQL queries, including SQL embedded in notebooks (`spark.sql(...)`, `%sql` cells), for anti-patterns, lint issues, and…
Creates dbt models following project conventions. Use when working with dbt models for: (1) Creating new models (any layer -…
Debugs and fixes dbt errors systematically. Use when working with dbt errors for: (1) Task mentions "fix", "error", "broken",…
Develops and troubleshoots dbt incremental models. Use when working with incremental materialization for: (1) Creating new…
Documents dbt models and columns in schema.yml. Use when working with dbt documentation for: (1) Adding model descriptions or…