‹ 首页

migrating-sql-to-dbt

@altimateai · 收录于 1 周前

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.

适合你,如果正在把旧SQL脚本改造成dbt项目

/ 下载安装
migrating-sql-to-dbt.skill双击,或拖进 Claude 桌面版 / Cowork,即完成安装↓ .skill↓ .zip
用别的 agent?下载 .zip 解压,把文件夹放进它的技能目录
Claude Code~/.claude/skills/(项目级 .claude/skills/)
Codex CLI~/.codex/skills/
Cursor自动读取上面两处目录
其他工具见其文档的「skills」目录;两个下载是同一份文件,只是名字不同
/ 通过 npx 安装 校验哈希
npx oh-my-skill add altimateai/data-engineering-skills/migrating-sql-to-dbt
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- altimateai/data-engineering-skills/migrating-sql-to-dbt
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify altimateai/data-engineering-skills/migrating-sql-to-dbt
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
109GitHub stars
~612上下文体积 · 单文件
镜像托管

怎么用

技能原文 SKILL.md作者撰写 · MIT · a13847e

dbt Migration

Don't convert everything at once. Build and validate layer by layer.

Workflow
1. Analyze Legacy SQL
cat <legacy_sql_file>

Identify all tables referenced in the query.

2. Check What Already Exists
# Search for existing models/sources that reference the table
grep -r "<table_name>" models/ --include="*.sql" --include="*.yml"
find models/ -name "*.sql" | xargs grep -l "<table_name>"

For each table referenced in the legacy SQL:

  1. Check if an existing model already references this table
  2. Check if a source definition exists
  3. If neither exists, ask user: "Table X not found - should I create it as a source?"

Only proceed to intermediate/mart layers after all dependencies exist.

3. Create Missing Sources
# models/staging/sources.yml
version: 2

sources:
  - name: raw_database
    schema: raw_schema
    tables:
      - name: orders
        description: Raw orders from source system
      - name: customers
        description: Raw customer records
4. Build Staging Layer

One staging model per source table. Follow existing project naming conventions.

Build before proceeding:

dbt build --select <staging_model>
5. Build Intermediate Layer (if needed)

Extract complex joins/logic into intermediate models.

Build incrementally:

dbt build --select <intermediate_model>
6. Build Mart Layer

Final business-facing model with aggregations.

7. Validate Migration
# Build entire lineage
dbt build --select +<final_model>
dbt show --select <final_model>
Migration Checklist
  • [ ] All source tables identified and documented
  • [ ] Sources.yml created with descriptions
  • [ ] Staging models: 1:1 with sources, renamed columns
  • [ ] Intermediate models: business logic extracted
  • [ ] Mart models: final aggregations
  • [ ] Each layer compiles successfully
  • [ ] Each layer builds successfully
  • [ ] Row counts match original (manual validation)
  • [ ] Tests added for key constraints
Common Migration Patterns
  • Nested subqueries → Separate models (staging → intermediate → mart)
  • Temp tables → Ephemeral materialization {{ config(materialized='ephemeral') }}
  • Hardcoded values → Variables {{ var("name") }}
Anti-Patterns
  • Converting entire legacy query to single dbt model
  • Skipping the staging layer
  • Not validating each layer before proceeding
  • Keeping hardcoded values instead of using variables
  • Not documenting business logic during migration
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。