Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ target**
logs/
manifest.json
static_index.html
!mise.toml
7 changes: 7 additions & 0 deletions dbt/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export DB_HOST=redshift-something.civis.orgs.civis.io
export DB_NAME=dev
export DB_PORT=5432
export DB_TYPE=redshift
export DB_CREDENTIAL_PASSWORD=replace-with-actual-password
export DB_CREDENTIAL_USERNAME=someuser
export DBT_SCHEMA=someschema
1 change: 1 addition & 0 deletions dbt/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ target/
.user.yml
logs/
target.tar.gz
.env
1 change: 1 addition & 0 deletions dbt/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
39 changes: 39 additions & 0 deletions dbt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,45 @@ This directory contains the configuration files, models, and seeds for the dbt (
- `stg_payments.sql`: SQL model for staging payments.
- `seeds/`: Directory containing seed files for dbt.

## Essential dbt Commands

### Core Development Commands
- `dbt run` - Executes your models to create tables/views in the database
- `dbt test` - Runs data quality tests defined in your models
- `dbt build` - Runs models and tests together (recommended workflow)
- `dbt compile` - Compiles SQL without executing (useful for syntax checking)

### Data Management Commands
- `dbt seed` - Loads CSV files from `seeds/` directory into your database
- `dbt snapshot` - Creates snapshots for slowly changing dimensions
- `dbt clean` - Removes compiled files and artifacts from your project

### Project Management Commands
- `dbt deps` - Downloads package dependencies defined in `packages.yml`
- `dbt debug` - Tests database connections and validates project setup
- `dbt docs generate` - Creates documentation for your project
- `dbt docs serve` - Serves documentation locally in your browser

### Selection and Targeting
- `dbt run --select model_name` - Run a specific model
- `dbt run --select +model_name` - Run model and all its upstream dependencies
- `dbt run --select model_name+` - Run model and all its downstream dependencies
- `dbt test --select source:*` - Test all source data freshness and quality
- `dbt run --select staging.*` - Run all models in the staging folder

### Useful Flags
- `--full-refresh` - Rebuild incremental models completely from scratch
- `--fail-fast` - Stop execution on first failure
- `--target dev` - Use a specific profile target (dev, prod, etc.)
- `--vars '{key: value}'` - Pass variables to your dbt project

### Typical Workflow for This Project
1. `dbt seed` - Load the CSV files from seeds/ into your database
2. `dbt run --select staging.*` - Run staging models (stg_customers, stg_orders, stg_payments)
3. `dbt run --select customers orders` - Run final transformation models
4. `dbt test` - Validate data quality with tests
5. `dbt docs generate && dbt docs serve` - Generate and view documentation

## Configuration

### dbt_project.yml
Expand Down
8 changes: 8 additions & 0 deletions dbt/do-thing.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# dbt test --select dbt_project.yml --project-dir /workspace/platform-code-examples/dbt --profiles-dir /workspace/platform-code-examples/dbt --target redshift_adapter
# curl -LsSf https://astral.sh/uv/install.sh | sh
# sudo apt-get install build-essential procps curl git
# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
# awk -F: '{printf "%s:%s\n",$1,$3}' /etc/passwd
curl https://mise.run | sh
6 changes: 6 additions & 0 deletions dbt/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def main():
print("Hello from dbt!")


if __name__ == "__main__":
main()
16 changes: 8 additions & 8 deletions dbt/profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ dbt-civis:
target: redshift_adapter
outputs:
redshift_adapter:
type: "{{ env_var('DATABASE_TYPE') }}"
host: "{{ env_var('DATABASE_HOST') }}"
port: "{{ env_var('DATABASE_PORT') | as_number }}"
user: "{{ env_var('DATABASE_USERNAME') }}"
pass: "{{ env_var('DBT_ENV_SECRET_DATABASE_PASSWORD') }}"
dbname: "{{ env_var('DATABASE_NAME') }}"
type: "{{ env_var('DB_TYPE') }}"
host: "{{ env_var('DB_HOST') }}"
port: "{{ env_var('DB_PORT') | as_number }}"
user: "{{ env_var('DB_CREDENTIAL_USERNAME') }}"
pass: "{{ env_var('DB_CREDENTIAL_PASSWORD') }}"
dbname: "{{ env_var('DB_NAME') }}"
schema: "{{ env_var('DBT_SCHEMA') }}"
threads: 4

bigquery_service_account_adapter:
type: "{{ env_var('DATABASE_TYPE') }}"
type: "{{ env_var('DB_TYPE') }}"
method: "{{ env_var('GCP_AUTH_METHOD') }}"
project: "{{ env_var('GCP_PROJECT_ID') }}"
schema: "{{ env_var('DBT_SCHEMA') }}"
Expand All @@ -21,7 +21,7 @@ dbt-civis:

bigquery_oauth_adapter:
threads: 4 # Must be a value of 1 or greater
type: "{{ env_var('DATABASE_TYPE') }}"
type: "{{ env_var('DB_TYPE') }}"
method: "{{ env_var('GCP_AUTH_METHOD') }}"
project: "{{ env_var('GCP_PROJECT_ID') }}"
schema: "{{ env_var('DBT_SCHEMA') }}"
Expand Down
7 changes: 7 additions & 0 deletions dbt/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[project]
name = "dbt"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []
11 changes: 11 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[env]
_.python.venv = { path = ".venv", create = true }

[settings]
python.uv_venv_auto = true

[tools]
jq = "latest"
python = "3.12"
uv = "latest"

Empty file added newfile.txt
Empty file.