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 113 stars 8 forks Updated 1 weeks ago MIT

Install

View on GitHub

Quality Score: 85/100

Stars 20%
68
Recency 20%
90
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
6 months ago
Last Updated
1 weeks ago
Language
N/A
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category

Data & Documents Listed

dbt-patterns

dbt model design, ref chains, sources, tests, macros, incremental strategies, materializations, and documentation best practices. Use this skill whenever the user is writing or reviewing dbt models, configuring dbt tests, designing model layers (staging/intermediate/marts), asking about incremental models, choosing materializations, writing macros, setting up sources.yml, or troubleshooting dbt run/test failures. Also trigger when the user mentions dbt refs, lineage graphs, model dependencies, dbt Cloud, the dbt CLI, or when they want to transform data already in the warehouse using SQL. If the project uses dbt at all, this skill should be active for any transformation questions.

1 Updated 1 weeks ago
Methasit-Pun
AI & Automation Solid

creating-dbt-models

Creates dbt models following project conventions. Use when working with dbt models for: (1) Creating new models (any layer - discovers project's naming conventions first) (2) Task mentions "create", "build", "add", "write", "new", or "implement" with model, table, or SQL (3) Modifying existing model logic, columns, joins, or transformations (4) Implementing a model from schema.yml specs or expected output requirements Discovers project conventions before writing. Runs dbt build (not just compile) to verify.

113 Updated 1 weeks ago
AltimateAI
Data & Documents Solid

migrating-sql-to-dbt

Converts legacy SQL to modular dbt models. Use when migrating SQL to dbt for: (1) Converting stored procedures, views, or raw SQL files to dbt models (2) Task mentions "migrate", "convert", "legacy SQL", "transform to dbt", or "modernize" (3) Breaking monolithic queries into modular layers (discovers project conventions first) (4) Porting existing data pipelines or ETL to dbt patterns Checks for existing models/sources, builds and validates layer by layer.

113 Updated 1 weeks ago
AltimateAI