📘 Introduction
Now that dbt CLI is installed, it’s time to create your first dbt project. In this module, you’ll:
- 
Initialize a dbt project 
- 
Connect it to a data warehouse (we’ll use Snowflake or PostgreSQL) 
- 
Understand the project folder structure 
- 
Create and run your first model 
Let’s dive in and turn raw data into analytics-ready models using just SQL.
🧰 What You’ll Need
- 
dbt CLI installed ( dbt --version)
- 
Access to Snowflake or Postgres (other adapters also work) 
- 
Terminal or command prompt 
- 
Basic SQL knowledge 
🚀 Step-by-Step: Create a dbt Project
🔹 Step 1: Initialize Your Project
In terminal or CMD, navigate to your workspace and run:
dbt init my_dbt_project
Replace my_dbt_project with your preferred name.
🔹 Step 2: Choose Your Adapter
During the init process, dbt will ask you to choose a warehouse adapter.
For example:
- 
snowflakefor Snowflake
- 
postgresfor PostgreSQL
Follow the prompts and confirm project setup.
🔹 Step 3: Understand Project Structure
After setup, you’ll see folders like:
my_dbt_project/
├── dbt_project.yml # Project config file
├── models/ # Where your SQL models live
├── snapshots/ # Optional - point-in-time copies
├── seeds/ # Static CSV data files
├── macros/ # Reusable SQL logic (Jinja)
└── target/ # Output folder (autogenerated)
🔹 Step 4: Set Up Your Profile
dbt connects to the warehouse using a profiles.yml file.
Location:
- 
Windows: C:\Users\<yourname>\.dbt\profiles.yml
- 
Mac/Linux: ~/.dbt/profiles.yml
Snowflake Example:
my_dbt_project:
target: dev
outputs:
dev:
type: snowflake
account: your_account
user: your_user
password: your_password
role: your_role
database: your_database
warehouse: your_warehouse
schema: analytics
threads: 1
🔹 Step 5: Test the Connection
Inside your project folder, run:
dbt debug
✅ You should see:
All checks passed! Connection is working.
🔹 Step 6: Create and Run Your First Model
Create a file:
📄 models/first_model.sql
Paste this simple model:
SELECT 1 AS id, 'dbt works!' AS message
🎉 That’s it! Your first model is live in your data warehouse.
💡 Pro Tips
- 
Keep models small and modular — one concept per file 
- 
Use Jinja templating for dynamic logic (we’ll cover this in Module 4) 
- 
Use dbt run --select model_nameto run individual models
📌 What’s Next?
📍 Next Module: Create Modular dbt Models Using SQL + Jinja
You’ll learn to layer models and add reusable SQL logic with Jinja templating.
No comments:
Post a Comment