Agent skill

dbt-migration

Convert database DDL from any source platform to dbt models compatible with Snowflake. This skill should be used when converting views, tables, or stored procedures from Snowflake, Teradata, Oracle, SQL Server, Redshift, BigQuery, PostgreSQL, DB2, Hive, Vertica, or Sybase to dbt code, generating schema.yml files with tests and documentation, or migrating existing SQL to follow dbt best practices.

Stars 163
Forks 31

Install this agent skill to your Project

npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/dbt-migration-sfc-gh-dflippo-snowflake-dbt-demo

SKILL.md

Database to dbt Model Conversion

Purpose

Transform database DDL (views, tables, stored procedures) from any source platform into production-quality dbt models compatible with Snowflake, maintaining the same business logic and data transformation steps while following dbt best practices.

When to Use This Skill

Activate this skill when users ask about:

  • Converting database views or tables to dbt models
  • Migrating stored procedures to dbt
  • Translating SQL syntax from one database to Snowflake
  • Generating schema.yml files with tests and documentation
  • Handling database-specific syntax conversions

Task Description

You are a database engineer working for a hospital system. You need to convert SQL DDL to equivalent dbt code compatible with Snowflake, maintaining the same business logic and data transformation steps while following dbt best practices.

Input Requirements

I will provide you the SQL DDL to convert. Please ask for the source database platform if not obvious from the syntax.

Audience

The code will be executed by data engineers who are learning Snowflake and dbt.

Output Requirements

Generate the following:

  1. One or more dbt models with complete SQL for every column
  2. A corresponding schema.yml file with appropriate tests and documentation
  3. A config block with materialization strategy
  4. Explanation of key changes and architectural decisions
  5. Inline comments highlighting any syntax that was converted

Conversion Guidelines

General Principles

  • Replace procedural logic with declarative SQL where possible
  • Break down complex procedures into multiple modular dbt models
  • Implement appropriate incremental processing strategies
  • Maintain data quality checks through dbt tests
  • Use Snowflake SQL functions rather than macros whenever possible

Sample Response Format

sql
-- dbt model: models/[domain]/[target_schema_name]/model_name.sql
{{ config(materialized='view') }}

/* Original Object: [source_db].[schema].[object_name]
 Source Platform: [Teradata|Oracle|SQL Server|etc.]
 Purpose: [brief description]
 Conversion Notes: [key changes]
 Description: [SQL logic description] */

WITH source_data AS (
 SELECT
 COLUMN1 AS COLUMN1_ALIAS,
 COLUMN2 AS COLUMN2_ALIAS,
 COLUMN3 AS COLUMN3_ALIAS,
 COLUMN4 AS COLUMN4_ALIAS
 FROM {{ ref('upstream_model') }}
),
transformed_data AS (
 SELECT
 UPPER(COLUMN1) AS COLUMN_ALIAS1,
 LOWER(COLUMN2) AS COLUMN_ALIAS2,
 COLUMN3 || COLUMN4 AS COLUMN_ALIAS3
 FROM source_data
)
SELECT
 COLUMN_ALIAS1,
 COLUMN_ALIAS2,
 COLUMN_ALIAS3
FROM transformed_data
yaml
# models/[domain]/[target_schema_name]/schema.yml
version: 2

models:
 - name: model_name
 description: "Table description; converted from [Source Platform] [Original object name]"
 columns:
 - name: COLUMN_ALIAS1
 description: "Column description; Primary key"
 tests:
 - unique
 - not_null
 - name: COLUMN_ALIAS2
 description: "Column description; Foreign key to OTHER_TABLE"
 tests:
 - relationships:
 to: ref('OTHER_TABLE')
 field: OTHER_TABLE_KEY
 - name: COLUMN_ALIAS3
 description: "Column description"
yaml
# dbt_project.yml
models:
  my_project:
  ? [domain]
  ? [target_schema_name]
  +schema: [target_schema_name]

Specific Translation Rules

dbt Specific Requirements:

  • If the source is a view, use a view materialization in dbt
  • Include appropriate dbt model configuration (materialization type)
  • Add documentation blocks for a schema.yml
  • Add descriptions for tables and columns
  • Include relevant tests
  • Define primary keys and relationships
  • Assume that upstream objects are models
  • Comprehensively provide all the columns in the output
  • Break complex procedures into multiple models if needed
  • Implement appropriate incremental strategies for large tables
  • Use Snowflake SQL functions rather than macros whenever possible

Performance Optimization:

  • Suggest clustering keys if needed
  • Recommend materialization strategy (view vs table)
  • Identify potential performance improvements

Dependencies:

  • List any upstream dependencies
  • Suggest model organization in dbt project

Validation Checklist

  • [] Source platform identified
  • [] Every DDL statement has been accounted for in the dbt models
  • [] SQL in models is compatible with Snowflake
  • [] All business logic preserved
  • [] All columns included in output
  • [] Data types correctly mapped
  • [] Functions translated to Snowflake equivalents
  • [] Materialization strategy selected
  • [] Tests added
  • [] SQL logic description complete
  • [] Table descriptions added
  • [] Column descriptions added
  • [] Dependencies correctly mapped
  • [] Incremental logic (if applicable) verified
  • [] Inline comments added for converted syntax

Related Skills

  • dbt-modeling: For CTE patterns and SQL structure guidance
  • dbt-testing: For implementing comprehensive dbt tests
  • dbt-architecture: For project organization and folder structure
  • dbt-materializations: For choosing materialization strategies (view, table, incremental, snapshots)
  • dbt-performance: For clustering keys, warehouse sizing, and query optimization
  • dbt-commands: For running dbt commands and model selection syntax
  • dbt-core: For dbt installation, configuration, and package management
  • snowflake-cli: For executing SQL and managing Snowflake objects

Supported Source Databases

Database Key Considerations
Snowflake Native syntax, focus on dbt patterns and best practices
Teradata QUALIFY, ANSI/TERA session modes, volatile tables, SET/MULTISET, BTEQ/FastLoad/MultiLoad scripts, DBC views
Oracle PL/SQL, DBMS_* packages, ROWNUM/ROWID, CONNECT BY, sequences, collections/records, wrapped objects, DATE includes time
SQL Server / Azure Synapse T-SQL procedures, IDENTITY, TOP, #temp tables, TRY...CATCH, sys.* tables, ANSI_NULLS/QUOTED_IDENTIFIER
Amazon Redshift DISTKEY/SORTKEY, PL/pgSQL procedures, system catalogs (pg_, stl_, stv_), COPY/UNLOAD
Google BigQuery UNNEST, STRUCT/ARRAY types, backtick identifiers, IS TRUE/FALSE operators, SAFE_* functions
PostgreSQL / Greenplum / Netezza Array expressions (<> ALL, = ANY), CHAR padding differences, psql commands, distribution keys
IBM DB2 Inline SQL PL, FETCH FIRST, CONTINUE/EXIT handlers, compound statements
Hive / Spark / Databricks External tables, PARTITIONED BY, LATERAL VIEW, file formats (PARQUET, ORC), UDFs
Vertica Projections, flex tables, case sensitivity with quotes, ANY/ALL array predicates
Sybase T-SQL variant, different built-in functions, SELECT syntax differences

Translation References

Detailed syntax translation guides are available in the translation-references/ folder.

Copyright Notice: The translation reference documentation in this repository is derived from Snowflake SnowConvert Documentation and is © Copyright Snowflake Inc. All rights reserved. Used for reference purposes only.

Full Translation Reference Index

Folder Description
bigquery BigQuery
db2 IBM DB2
general Cross-database references
hive Hive, Spark, Databricks
oracle Oracle
postgres PostgreSQL, Greenplum, Netezza
redshift Amazon Redshift
ssis SSIS
sybase Sybase IQ
teradata Teradata
transact SQL Server / Azure Synapse
vertica Vertica

Full Translation Reference Index (Expanded)

Folder Description
bigquery BigQuery
bigquery CREATE TABLE (unsupported options)
bigquery CREATE VIEW
bigquery Data types mapping
bigquery Supported Built-in functions
bigquery Quoted identifier syntax
bigquery IS operators (IS NULL, IS TRUE, etc.)
db2 IBM DB2
db2 CONTINUE handler behavior
db2 CREATE FUNCTION
db2 CREATE PROCEDURE
db2 CREATE TABLE syntax
db2 CREATE VIEW
db2 Data types
db2 EXIT handler behavior
db2 FROM clause
db2 SELECT statement
general Cross-database references
general Alphabetical list of Built-in functions (cross-platform)
general Subqueries in FROM/WHERE clauses
hive Hive, Spark, Databricks
hive Built-in functions
hive Data types mapping
hive Supported DDL statements
hive CREATE EXTERNAL TABLE
hive CREATE VIEW
hive SELECT
hive CREATE TABLE
oracle Oracle
oracle Data types and arithmetic
oracle ANY types for flexible parameter/column typing
oracle Built-in data types (VARCHAR2, NUMBER, DATE, etc.)
oracle ROWID types
oracle Spatial and geographic types
oracle User-defined types (UDTs)
oracle XML types
oracle Literals and constant values
oracle Built-in packages.
oracle Power BI connection repointing
oracle Functions
oracle Custom UDFs for Oracle function equivalence
oracle PL/SQL to JavaScript
oracle Helper functions for Oracle features
oracle Assignment statements and PL/SQL basics
oracle Collections and Records
oracle CREATE FUNCTION
oracle CREATE PROCEDURE
oracle Cursors
oracle DML with PL/SQL elements
oracle Helper functions for unsupported Oracle features
oracle CREATE PACKAGE
oracle ROWID pseudocolumn
oracle Sample data used in examples
oracle SQL*Plus to SnowSQL
oracle JOIN operations
oracle SELECT
oracle Oracle SQL syntax differences and translations
oracle Materialized View to Dynamic Table
oracle CREATE TABLE
oracle CREATE VIEW
oracle CREATE TYPE (UDTs)
oracle Wrapped/encrypted objects
postgres PostgreSQL, Greenplum, Netezza
postgres Netezza data types
postgres PostgreSQL data types
postgres Greenplum Materialized View
postgres Materialized View to Dynamic Table
postgres Greenplum CREATE TABLE
postgres Netezza CREATE TABLE
postgres PostgreSQL CREATE TABLE
postgres PostgreSQL CREATE VIEW
postgres Power BI connection repointing
postgres Built-in functions
postgres <> ALL & = ANY array expressions
postgres PSQL commands
postgres String comparison behavior
redshift Amazon Redshift
redshift Power BI connection repointing
redshift Literals
redshift Names and identifiers
redshift BETWEEN condition
redshift CONTINUE handler emulation
redshift Data types
redshift EXIT handler via EXCEPTION blocks
redshift Expression lists
redshift Built-in functions
redshift CREATE TABLE AS
redshift CREATE TABLE
redshift Supported SQL statements
redshift System catalog views
redshift CREATE PROCEDURE
redshift SELECT INTO
redshift SELECT
ssis SSIS
sybase Sybase IQ
sybase Built-in functions
sybase CREATE TABLE
sybase CREATE VIEW
sybase Data types mapping
sybase SELECT statement
teradata Teradata
teradata Considerations for migrating data from Teradata
teradata Power BI connection repointing
teradata Helper functions for procedures
teradata BTEQ, FastLoad, MultiLoad, TPT scripts to Python
teradata BTEQ to Python
teradata FastLoad to Python
teradata MultiLoad to Python
teradata Helper classes for Teradata script to Python conversion
teradata TPT translation
teradata Scripts to Snowflake SQL
teradata BTEQ to Snowflake SQL
teradata Common script statements
teradata MultiLoad to Snowflake SQL
teradata ANSI vs TERA session modes
teradata Iceberg table transformations
teradata Teradata SQL to Snowflake
teradata Analytic functions
teradata Data types
teradata Equivalents for DBC objects and columns
teradata DDL statements
teradata DML statements
teradata Built-in functions
teradata GET DIAGNOSTICS EXCEPTION
teradata ABORT and ROLLBACK
transact SQL Server / Azure Synapse
transact Power BI connection repointing
transact ALTER statements
transact ANSI_NULLS setting
transact Built-in functions
transact Built-in procedures
transact Exception handling with TRY...CATCH
transact User Defined Functions
transact CREATE INDEX
transact Materialized View to Dynamic Table
transact BEGIN/COMMIT transactions
transact CREATE PROCEDURE to JavaScript
transact CREATE TABLE
transact CREATE VIEW
transact Data types mapping
transact DML statements and expressions
transact Exception handling with TRY...CATCH
transact General statements
transact QUOTED_IDENTIFIER setting
transact SELECT in procedures
transact System tables
vertica Vertica
vertica Built-in functions
vertica CREATE TABLE
vertica CREATE VIEW
vertica Data types mapping
vertica Case sensitivity and quoted identifiers
vertica Vertica Operators
vertica ANY & ALL array predicates

Expand your agent's capabilities with these related and highly-rated skills.

Didn't find tool you were looking for?

Be as detailed as possible for better results