A starter for setting up dbt test cases.
Requirements:
- Docker
- dbt
- Python
Unless otherwise specified, run all commands from the repo root.
-
Set up Postgres. We use the pagila database.
docker pull postgres # start (add -d before the last 'postgres' to run in background) docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=secret -d postgres
-
Ingest sample data into the database
# create database echo 'CREATE DATABASE pagila' | docker exec -i postgres psql -U postgres # schema objects cat ./db/pagila-schema.sql | docker exec -i postgres psql -U postgres -d pagila # data cat ./db/pagila-data.sql | docker exec -i postgres psql -U postgres -d pagila
To confirm ingestion, enter psql shell again (using
docker exec -it postgres psql -U postgres -d pagila
) and run# list tables \dt
-
Set up dbt (order matters!):
# create ~/.dbt directory to copy profiles.yml mkdir ~/.dbt # copy profiles.yml to ~/.dbt/ cp profiles.yml ~/.dbt/
-
Generate files for dbt:
./generate.sh