CREATE TABLE IF NOT EXISTS edu.users (
user_id SERIAL, -- уникальный идентификатор
name VARCHAR(255),
email VARCHAR(255),
status VARCHAR(50),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
); sudo apt update
sudo apt install -y python3 python3-pip python3 -m venv dbt-env pip install dbt-postgres dbt init my_dbt_project test_prj:
target: dev
outputs:
dev:
type: postgres
threads: 4
host: "localhost"
port: 5432
user: "your_username"
pass: "your_password"
dbname: "datadb"
schema: "edu"
keepalives_idle: 0
connect_timeout: 10
search_path: public dbt debug Connection test: [OK connection ok] {{ config(
materialized='table'
) }}
select user_id,
name,
email,
status,
created_at
from edu.users version: 2
models:
- name: stg_users
description: "Таблица пользователей после первичной очистки"
columns:
- name: user_id
description: "Уникальный идентификатор пользователя"
tests:
- not_null
- unique
- name: email
description: "Email пользователя"
tests:
- not_null
- unique
- name: status
description: "Статус пользователя"
tests:
- accepted_values:
values: ['active', 'inactive', 'banned']
dbt run
dbt test dbt run --select stg_users
dbt test --select stg_users
pip install soda-core-postgres mkdir soda_project && cd soda_project data_source postgres_connection:
type: postgres
connection:
host: localhost
port: 5432
username: your_username
password: your_pass
database: datadb
schema: edu checks for users:
- missing_count(user_id) = 0
- duplicate_count(user_id) = 0
- missing_count(email) = 0
- duplicate_count(email) = 0
- missing_percent(status) = 100%:
missing values: ['active', 'inactive', 'banned'] soda scan -d postgres_connection -c connection.yml checks.yml