refactoring-dbt-models
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "refactoring-dbt-models":https://skillpi.com/zh/skills/deepskill-e65e8cfef5a60768cd36ea6e2826434aad3244f4c84f594582f5eca03dad175b。安装前核对上游来源和版本:https://github.com/AltimateAI/data-engineering-skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
用于安全重构 dbt 模型并进行下游影响分析。适用于提到“重构/重组/提取/拆分/分解/重新组织”的任务、将 CTE 提取为中间模型或创建宏、修改有下游使用者的模型逻辑,以及重命名列、更改类型或重组模型依赖。在更改前分析所有下游依赖关系。
介绍来源: third_party · AltimateAI · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 输入和输出
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
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.dbt Refactoring
Find ALL downstream dependencies before changing. Refactor in small steps. Verify output after each change.
Workflow
1. Analyze Current Model
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.
# 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:
# 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 | Separate into focused models |
5. Execute Refactoring
Pattern: Extract CTE to Model
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_enriched
After:
-- 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_enriched
Pattern: Extract to Macro
Before (repeated in multiple models):
case
when amount < 0 then 'refund'
when amount = 0 then 'zero'
else 'positive'
end as amount_category
After:
-- 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
6. Validate Changes
# 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
7. Verify Output Matches Original
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 10
8. Update Downstream Models
If changing output columns:
- Update all downstream refs
- Update schema.yml documentation
- Re-run downstream tests
Refactoring Checklist
- [ ] All downstream dependencies identified
- [ ] User informed of impact scope
- [ ] One change at a time
- [ ] Compile passes after each change
- [ ] Build passes after each change
- [ ] Output validated (row counts match)
- [ ] Documentation updated
- [ ] Tests still pass
Common Refactoring Triggers
| 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 |
Anti-Patterns
- Refactoring without checking downstream impact
- Making multiple changes at once
- Not validating output matches after refactoring
- Extracting prematurely (wait for 3+ uses)
- Breaking existing tests without updating them
当前收录版本
0.0.1
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 针对 dbt 模型重构这一数据工程高频需求,提供端到端解决方案
- 涵盖从依赖分析、重构执行到输出验证的完整闭环流程
亮点
- 触发条件清晰明确,覆盖重构、提取、拆分等典型场景
- 关键词定义准确,边界清晰,不易误触或漏触
待提升项
-
文档长度略长 原报告严重程度:轻微
SKILL.md 内容约 600 行,超出建议的 500 行上限
改进建议:可考虑将部分示例或检查清单移至独立文件,保持主文档简洁
亮点
- 结构完整,包含工作流、模式、检查清单和反模式
- 步骤划分清晰,有明确的出口条件和验证机制
亮点
- 提供具体的 dbt 命令和验证步骤,确保重构安全
- 强调下游影响分析和输出一致性验证,降低执行风险
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。