GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — data-stack-lab/dbt at main · technobasant/data-stack-lab

Expand file tree

/

dbt

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

dbt

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
macros
macros
 
 
models
models
 
 
snapshots
snapshots
 
 
tests
tests
 
 
README.md
README.md
 
 
dbt_project.yml
dbt_project.yml
 
 
profiles.yml
profiles.yml
 
 

README.md

Outline

dbt: a star schema with a Type 2 account dimension

The dbt project for data-stack-lab. It turns the raw sources into a Kimball star schema whose account dimension keeps history, built only from what monthly extracts of the application database showed. Results and method: README, MEASUREMENTS.

erDiagram
    dim_account ||--o{ fct_invoices : "version billed"
    dim_account ||--o{ fct_daily_usage : "version in effect"
    dim_date ||--o{ fct_invoices : invoice_date_key
    dim_date ||--o{ fct_daily_usage : date_key
    dim_plan ||--o{ dim_account : plan_id
    dim_account {
        string account_key PK "one per version"
        bigint account_id "shared by every version"
        int version_number
        string plan_name
        string status
        timestamp valid_from
        timestamp valid_to "exclusive; 9999-12-31 if current"
        boolean is_current
    }
    fct_invoices {
        string invoice_id PK
        string account_key FK
        int invoice_date_key FK
        decimal amount_usd
    }
    fct_daily_usage {
        string account_key FK
        date activity_date
        int date_key FK
        bigint events
        bigint active_users
    }
Loading

Layers

Layer Schema What it does
sources raw as loaded: the current accounts extract, users, plans, invoices, events
snapshot snapshots snap_accounts: every version an extract showed, timestamp strategy on updated_at
staging staging views: types, e-mail normalised, redelivered events dropped
marts marts tables: dim_account (Type 2), dim_plan, dim_date, dim_user (Type 1), fct_invoices, fct_daily_usage, revenue_by_plan

Bus matrix

Fact (grain) dim_account dim_date dim_plan (through the account version)
fct_invoices (one invoice) ✓ ✓ ✓
fct_daily_usage (account version × day) ✓ ✓ ✓

Tests

  • Contracts enforced on dim_account, fct_invoices and fct_daily_usage: column names and types are checked before the table is built.
  • Data tests (46): keys unique and not null, relationships from facts to dimensions, accepted values, one current version per account, validity windows that neither overlap nor leave gaps (tests/generic/valid_windows.sql), the usage grain, and two reconciliations: the invoice fact holds exactly the billing export's invoices and money, and daily usage counts every event once.
  • Unit tests (3): a redelivered event counts once; the first version reaches back to signup and the open one ends at 9999-12-31; an invoice takes the version in effect when it was billed.

Running it alone

From the repository root, after make data:

uv run python scripts/warehouse.py   # 13 snapshot loads, then dbt build
cd dbt && DUCKDB_PATH=../data/warehouse.duckdb uv run dbt docs generate --profiles-dir .

profiles.yml has two targets: duckdb (the default, and the only one CI builds this project on) and databricks (databricks/dbt_build.py builds this project on a Databricks SQL warehouse; see databricks/README.md). The Snowflake and BigQuery projects would add their own targets and run this same project.

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.