refactor: multi-dashboard structural migration
Some checks failed
CI / lint-and-test (pull_request) Has been cancelled
Some checks failed
CI / lint-and-test (pull_request) Has been cancelled
- Rename dbt project from toronto_housing to portfolio - Restructure dbt models into domain subdirectories: - shared/ for cross-domain dimensions (dim_time) - staging/toronto/, intermediate/toronto/, marts/toronto/ - Update SQLAlchemy models for raw_toronto schema - Add explicit cross-schema FK relationships for FactRentals - Namespace figure factories under figures/toronto/ - Namespace notebooks under notebooks/toronto/ - Update Makefile with domain-specific targets and env loading - Update all documentation for multi-dashboard structure This enables adding new dashboard projects (e.g., /football, /energy) without structural conflicts or naming collisions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
name: 'toronto_housing'
|
||||
version: '1.0.0'
|
||||
name: 'portfolio'
|
||||
config-version: 2
|
||||
|
||||
profile: 'toronto_housing'
|
||||
profile: 'portfolio'
|
||||
|
||||
model-paths: ["models"]
|
||||
analysis-paths: ["analyses"]
|
||||
@@ -16,13 +15,19 @@ clean-targets:
|
||||
- "dbt_packages"
|
||||
|
||||
models:
|
||||
toronto_housing:
|
||||
portfolio:
|
||||
shared:
|
||||
+materialized: view
|
||||
+schema: shared
|
||||
staging:
|
||||
+materialized: view
|
||||
+schema: staging
|
||||
toronto:
|
||||
+materialized: view
|
||||
+schema: staging
|
||||
intermediate:
|
||||
+materialized: view
|
||||
+schema: intermediate
|
||||
toronto:
|
||||
+materialized: view
|
||||
+schema: intermediate
|
||||
marts:
|
||||
+materialized: table
|
||||
+schema: marts
|
||||
toronto:
|
||||
+materialized: table
|
||||
+schema: marts
|
||||
|
||||
33
dbt/models/shared/_shared.yml
Normal file
33
dbt/models/shared/_shared.yml
Normal file
@@ -0,0 +1,33 @@
|
||||
version: 2
|
||||
|
||||
models:
|
||||
- name: stg_dimensions__time
|
||||
description: "Staged time dimension - shared across all projects"
|
||||
columns:
|
||||
- name: date_key
|
||||
description: "Primary key (YYYYMM format)"
|
||||
data_tests:
|
||||
- unique
|
||||
- not_null
|
||||
- name: full_date
|
||||
description: "First day of month"
|
||||
data_tests:
|
||||
- not_null
|
||||
- name: year
|
||||
description: "Calendar year"
|
||||
data_tests:
|
||||
- not_null
|
||||
- name: month
|
||||
description: "Month number (1-12)"
|
||||
data_tests:
|
||||
- not_null
|
||||
- name: quarter
|
||||
description: "Quarter (1-4)"
|
||||
data_tests:
|
||||
- not_null
|
||||
- name: month_name
|
||||
description: "Month name"
|
||||
data_tests:
|
||||
- not_null
|
||||
- name: is_month_start
|
||||
description: "Always true (monthly grain)"
|
||||
25
dbt/models/shared/_sources.yml
Normal file
25
dbt/models/shared/_sources.yml
Normal file
@@ -0,0 +1,25 @@
|
||||
version: 2
|
||||
|
||||
sources:
|
||||
- name: shared
|
||||
description: "Shared dimension tables used across all dashboards"
|
||||
database: portfolio
|
||||
schema: public
|
||||
tables:
|
||||
- name: dim_time
|
||||
description: "Time dimension (monthly grain) - shared across all projects"
|
||||
columns:
|
||||
- name: date_key
|
||||
description: "Primary key (YYYYMM format)"
|
||||
- name: full_date
|
||||
description: "First day of month"
|
||||
- name: year
|
||||
description: "Calendar year"
|
||||
- name: month
|
||||
description: "Month number (1-12)"
|
||||
- name: quarter
|
||||
description: "Quarter (1-4)"
|
||||
- name: month_name
|
||||
description: "Month name"
|
||||
- name: is_month_start
|
||||
description: "Always true (monthly grain)"
|
||||
@@ -1,9 +1,10 @@
|
||||
-- Staged time dimension
|
||||
-- Source: dim_time table
|
||||
-- Source: shared.dim_time table
|
||||
-- Grain: One row per month
|
||||
-- Note: Shared dimension used across all dashboard projects
|
||||
|
||||
with source as (
|
||||
select * from {{ source('toronto_housing', 'dim_time') }}
|
||||
select * from {{ source('shared', 'dim_time') }}
|
||||
),
|
||||
|
||||
staged as (
|
||||
@@ -1,10 +1,10 @@
|
||||
version: 2
|
||||
|
||||
sources:
|
||||
- name: toronto_housing
|
||||
description: "Toronto housing data loaded from CMHC and City of Toronto sources"
|
||||
- name: toronto
|
||||
description: "Toronto data loaded from CMHC and City of Toronto sources"
|
||||
database: portfolio
|
||||
schema: public
|
||||
schema: raw_toronto
|
||||
tables:
|
||||
- name: fact_rentals
|
||||
description: "CMHC annual rental survey data by zone and bedroom type"
|
||||
@@ -16,12 +16,6 @@ sources:
|
||||
- name: zone_key
|
||||
description: "Foreign key to dim_cmhc_zone"
|
||||
|
||||
- name: dim_time
|
||||
description: "Time dimension (monthly grain)"
|
||||
columns:
|
||||
- name: date_key
|
||||
description: "Primary key (YYYYMMDD format)"
|
||||
|
||||
- name: dim_cmhc_zone
|
||||
description: "CMHC zone dimension with geometry"
|
||||
columns:
|
||||
@@ -18,15 +18,6 @@ models:
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: stg_dimensions__time
|
||||
description: "Staged time dimension"
|
||||
columns:
|
||||
- name: date_key
|
||||
description: "Date dimension key (YYYYMMDD)"
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
- name: stg_dimensions__cmhc_zones
|
||||
description: "Staged CMHC zone dimension"
|
||||
columns:
|
||||
@@ -6,8 +6,8 @@ with source as (
|
||||
select
|
||||
f.*,
|
||||
t.year as survey_year
|
||||
from {{ source('toronto_housing', 'fact_rentals') }} f
|
||||
join {{ source('toronto_housing', 'dim_time') }} t on f.date_key = t.date_key
|
||||
from {{ source('toronto', 'fact_rentals') }} f
|
||||
join {{ source('shared', 'dim_time') }} t on f.date_key = t.date_key
|
||||
),
|
||||
|
||||
staged as (
|
||||
@@ -3,7 +3,7 @@
|
||||
-- Grain: One row per zone-neighbourhood intersection
|
||||
|
||||
with source as (
|
||||
select * from {{ source('toronto_housing', 'bridge_cmhc_neighbourhood') }}
|
||||
select * from {{ source('toronto', 'bridge_cmhc_neighbourhood') }}
|
||||
),
|
||||
|
||||
staged as (
|
||||
@@ -3,7 +3,7 @@
|
||||
-- Grain: One row per zone
|
||||
|
||||
with source as (
|
||||
select * from {{ source('toronto_housing', 'dim_cmhc_zone') }}
|
||||
select * from {{ source('toronto', 'dim_cmhc_zone') }}
|
||||
),
|
||||
|
||||
staged as (
|
||||
@@ -3,7 +3,7 @@
|
||||
-- Grain: One row per neighbourhood per amenity type per year
|
||||
|
||||
with source as (
|
||||
select * from {{ source('toronto_housing', 'fact_amenities') }}
|
||||
select * from {{ source('toronto', 'fact_amenities') }}
|
||||
),
|
||||
|
||||
staged as (
|
||||
@@ -3,7 +3,7 @@
|
||||
-- Grain: One row per neighbourhood per census year
|
||||
|
||||
with source as (
|
||||
select * from {{ source('toronto_housing', 'fact_census') }}
|
||||
select * from {{ source('toronto', 'fact_census') }}
|
||||
),
|
||||
|
||||
staged as (
|
||||
@@ -3,7 +3,7 @@
|
||||
-- Grain: One row per neighbourhood per year per crime type
|
||||
|
||||
with source as (
|
||||
select * from {{ source('toronto_housing', 'fact_crime') }}
|
||||
select * from {{ source('toronto', 'fact_crime') }}
|
||||
),
|
||||
|
||||
staged as (
|
||||
@@ -3,7 +3,7 @@
|
||||
-- Grain: One row per neighbourhood (158 total)
|
||||
|
||||
with source as (
|
||||
select * from {{ source('toronto_housing', 'dim_neighbourhood') }}
|
||||
select * from {{ source('toronto', 'dim_neighbourhood') }}
|
||||
),
|
||||
|
||||
staged as (
|
||||
@@ -1,4 +1,4 @@
|
||||
toronto_housing:
|
||||
portfolio:
|
||||
target: dev
|
||||
outputs:
|
||||
dev:
|
||||
|
||||
Reference in New Issue
Block a user