Model Data in MotherDuck
Use this skill when creating data models, tables, designing schemas, choosing data types, defining relationships between tables, or restructuring data for analytical workloads.
Core Behavior
When a user asks questions like "build a data model", "model my data", or "create a transformation layer", the default output is a file-based project scaffold — not just SQL executed directly in the warehouse.
The project scaffold includes:
- SQL files organized by lifecycle stage (
raw/, staging/, analytics/)
- A manifest (
model_manifest.yml) defining the DAG: model names, dependencies, materialization strategy, and target database
This is a lightweight framework-agnostic convention for organizing SQL transformations that can be reviewed, versioned, and rerun.
Prerequisites
- MotherDuck connection established via
connect
- Existing source shape understood via
explore
- DuckDB SQL syntax available via
duckdb-sql
Default Posture
- Design for analytical reads, not transactional writes.
- Prefer wide denormalized tables and pre-aggregated serving tables over highly normalized OLTP-style schemas.
- Use fully qualified names and add comments to tables and columns.
- Use
NOT NULL aggressively; do not assume primary keys or foreign keys are enforced.
- Separate
raw, staging, and analytics lifecycle stages when the project is non-trivial.
- Always produce SQL files — never execute transformations directly in the warehouse without first writing them to files.
- Always produce a manifest — every model must declare its dependencies so the DAG is explicit and reproducible.
Workflow
- Inspect the current source tables and actual column types before designing new models.
- Choose the target lifecycle stage and grain for each modeled table. Map dependencies between models.
- Create the project directory structure with SQL files and manifest.
- Author each model as a standalone SQL file. Use explicit types, nullability, comments, and fully qualified names. Decide between a table, CTAS rebuild, or view based on freshness and cost.
- Fill in the manifest with model metadata: name, path, stage, materialization, database, and
depends_on references.
- Run the models against the warehouse and verify the resulting tables match expected grain and row counts.
Expected Project Structure
<project-name>/
models/
raw/
raw_<entity>.sql -- DDL for raw landing tables
staging/
stg_<entity>.sql -- Deduplicated, typed, filtered
analytics/
dim_<entity>.sql -- Dimension tables
fct_<entity>.sql -- Fact / metric tables
model_manifest.yml -- DAG: names, deps, materialization
When to Skip the Scaffold
If the user explicitly asks for a single table, a quick DDL statement, or an ad-hoc exploration query, produce the SQL directly. The scaffold is the default for modeling work — multi-table, multi-stage transformations with dependencies.
Open Next
references/MODELING_PLAYBOOK.md for schema patterns, data-type guidance, CTAS/view decisions, complex types, constraints, project scaffold conventions, and common modeling mistakes
Related Skills
duckdb-sql for type syntax and function details
query for executing DDL, rebuilds, and validation queries
explore for understanding the source schema before remodeling
load-data for ingestion paths that feed the modeled tables
1---2name: model-data-23description: Design and build database schemas and data models in MotherDuck. Produces a file-based project scaffold. Use when creating tables, choosing data types, defining relationships, or restructuring data for analytics workloads.4license: MIT5---67# Model Data in MotherDuck89Use this skill when creating data models, tables, designing schemas, choosing data types, defining relationships between tables, or restructuring data for analytical workloads.1011## Core Behavior1213**When a user asks questions like "build a data model", "model my data", or "create a transformation layer", the default output is a file-based project scaffold — not just SQL executed directly in the warehouse.**1415The project scaffold includes:1617- **SQL files** organized by lifecycle stage (`raw/`, `staging/`, `analytics/`)18- **A manifest** (`model_manifest.yml`) defining the DAG: model names, dependencies, materialization strategy, and target database1920This is a lightweight framework-agnostic convention for organizing SQL transformations that can be reviewed, versioned, and rerun.2122## Prerequisites2324- MotherDuck connection established via `connect`25- Existing source shape understood via `explore`26- DuckDB SQL syntax available via `duckdb-sql`2728## Default Posture2930- Design for analytical reads, not transactional writes.31- Prefer wide denormalized tables and pre-aggregated serving tables over highly normalized OLTP-style schemas.32- Use fully qualified names and add comments to tables and columns.33- Use `NOT NULL` aggressively; do not assume primary keys or foreign keys are enforced.34- Separate `raw`, `staging`, and `analytics` lifecycle stages when the project is non-trivial.35- Always produce SQL files — never execute transformations directly in the warehouse without first writing them to files.36- Always produce a manifest — every model must declare its dependencies so the DAG is explicit and reproducible.3738## Workflow39401. Inspect the current source tables and actual column types before designing new models.412. Choose the target lifecycle stage and grain for each modeled table. Map dependencies between models.423. Create the project directory structure with SQL files and manifest.434. Author each model as a standalone SQL file. Use explicit types, nullability, comments, and fully qualified names. Decide between a table, CTAS rebuild, or view based on freshness and cost.445. Fill in the manifest with model metadata: name, path, stage, materialization, database, and `depends_on` references.456. Run the models against the warehouse and verify the resulting tables match expected grain and row counts.4647## Expected Project Structure4849```50<project-name>/51 models/52 raw/53 raw_<entity>.sql -- DDL for raw landing tables54 staging/55 stg_<entity>.sql -- Deduplicated, typed, filtered56 analytics/57 dim_<entity>.sql -- Dimension tables58 fct_<entity>.sql -- Fact / metric tables59 model_manifest.yml -- DAG: names, deps, materialization60```6162## When to Skip the Scaffold6364If the user explicitly asks for a single table, a quick DDL statement, or an ad-hoc exploration query, produce the SQL directly. The scaffold is the default for **modeling work** — multi-table, multi-stage transformations with dependencies.6566## Open Next6768- `references/MODELING_PLAYBOOK.md` for schema patterns, data-type guidance, CTAS/view decisions, complex types, constraints, project scaffold conventions, and common modeling mistakes6970## Related Skills7172- `duckdb-sql` for type syntax and function details73- `query` for executing DDL, rebuilds, and validation queries74- `explore` for understanding the source schema before remodeling75- `load-data` for ingestion paths that feed the modeled tables