migrating-sql-to-dbt

migrating-sql-to-dbt is a skill for Claude Code from AltimateAI/data-engineering-skills. It costs 121 tokens per session (721 once invoked), scanned A, original, MIT.

A guide for converting older SQL, including stored procedures, views, and large query files, into dbt models. dbt is a tool for building and testing SQL transformations as organized project files.

In plain words
What is it for?
Use it to create source definitions, build staging and later models, and validate a migration from legacy SQL to dbt.
Why use it?
It breaks a large or difficult-to-maintain query into layers and checks that its source tables and dependencies exist before continuing.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the dbt-skills plugin — 7 skills shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/altimateai/data-engineering-skills/migrating-sql-to-dbt
Any agent
npx skills add AltimateAI/data-engineering-skills --skill migrating-sql-to-dbt
Clone the repo
git clone --depth 1 https://github.com/AltimateAI/data-engineering-skills

Made for: Claude Code.

Or install dbt-skills, the plugin that ships this one along with the rest of its 7 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for migrating-sql-to-dbt

README.md
[![agentmods](https://agentmods.dev/badge/skills/altimateai/data-engineering-skills/migrating-sql-to-dbt.svg)](https://agentmods.dev/skills/altimateai/data-engineering-skills/migrating-sql-to-dbt)
Your own site
<a href="https://agentmods.dev/skills/altimateai/data-engineering-skills/migrating-sql-to-dbt"><img src="https://agentmods.dev/badge/skills/altimateai/data-engineering-skills/migrating-sql-to-dbt.svg" alt="Measured on agentmods" height="20"></a>
Per session 121 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 721 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00121 $0.00721
Opus 5 $0.00060 $0.00360
Sonnet 5 $0.00024 $0.00144
Haiku 4.5 $0.00012 $0.00072

Measured 6d ago against content hash 38c6cae440d3, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

migrating-sql-to-dbt scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

Copies of this mod

1 near-identical copy found in the catalogue:

skills/dbt/migrating-sql-to-dbt/SKILL.md · 113 lines

How it starts

The opening of the file, as written. The whole thing — 113 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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

Read the full file on GitHub · 113 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 113 lines · 121 tokens per session scan A 38c6cae440d3

Subscribe to this mod's changes

migrating-sql-to-dbt is a skill published in the GitHub repository AltimateAI/data-engineering-skills (122 stars, last pushed 1mo ago), licensed MIT. It adds 121 tokens to every session and 721 once invoked, about $0.0006 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

explain-sql

Explain complex SQL queries in plain English with Mermaid data flow diagrams, performance annotations, and anti-pattern detection. Use when the user pastes a SQL query and asks "what does this do?", "explain this query", or needs to understand inherited SQL, CTEs, window functions, recursive queries, or dbt model…

adityawrk/analytics-with-claude-code · 72 tokens

sql-optimizer

Analyze and optimize slow SQL queries. Use when the user says a query is slow, asks to optimize or speed up SQL, wants to find anti-patterns, needs index recommendations, or asks for a query rewrite. Also use when EXPLAIN output shows full table scans or poor join strategies.

adityawrk/analytics-with-claude-code · 63 tokens

backend-patterns

Backend architecture patterns, API design, database optimization, and server-side best practices for Node.js, Express, and Next.js API routes.

Methasit-Pun/data_engineer_claude_skills · 31 tokens

dbt-patterns

The most important design decision in a dbt project is how to organize model layers. A clear layer structure means every model has exactly one place it belongs, and anyone reading the project can understand what each model does.

Methasit-Pun/data_engineer_claude_skills · 143 tokens

data-migration

Moving data between systems safely — cutover planning, backfill strategies, dual-write patterns, validation, rollback procedures, and zero-downtime migration techniques. Use this skill whenever the team is migrating from one database or warehouse to another (MySQL → Snowflake, Redshift → BigQuery, on-prem → cloud)…

Methasit-Pun/data_engineer_claude_skills · 160 tokens

schema-design

Data modeling for analytical workloads — star schema, snowflake schema, one big table (OBT), slowly changing dimensions (SCD), normalization tradeoffs, grain definition, and surrogate key strategies. Use this skill whenever the user is designing or reviewing a data warehouse schema, planning a fact/dimension table…

Methasit-Pun/data_engineer_claude_skills · 143 tokens