refactoring-dbt-models

Solid

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.

AI & Automation 124 stars 11 forks Updated yesterday MIT

Install

View on GitHub

Quality Score: 87/100

Stars 20%
70
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# dbt Refactoring **Find ALL downstream dependencies before changing. Refactor in small steps. Verify output after each change.** ## Workflow ### 1. Analyze Current Model ```bash cat models/<path>/<model_name>.sql ``` Identify refactoring opportunities: - CTEs longer than 50 lines → extract to intermediate model - Logic repeated across models → extract to macro - Multiple joins in sequence → split into steps - Complex WHERE clauses → extract to staging filter ### 2. Find All Downstream Dependencies **CRITICAL: Never refactor without knowing impact.** ```bash # 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." ### 3. Check What Columns Downstream Models Use **BEFORE changing any columns, check what downstream models reference:** ```bash # 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. ### 4. Plan Refactoring Strategy | Opportunity | Strategy | |-------------|----------| | Long CTE | Extract to intermediate model | | Repeated logic | Create macro in `macros/` | | Complex join | Split into intermediate models | | Multiple concerns...

Details

Author
AltimateAI
Repository
AltimateAI/data-engineering-skills
Created
8 months ago
Last Updated
yesterday
Language
N/A
License
MIT

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category