# Chapter 7 Lab: Build a Dimensional Sales Mart with SCD2 History

This lab builds a small but realistic TuranMart analytical mart. It reads deterministic CSV source files, constructs date, product, and customer dimensions, applies **SCD Type 2** history for customer region changes, writes a `fact_sales` table at order-line grain, and publishes a daily sales summary. The lab uses DuckDB so the workflow runs locally while preserving the modeling habits used in cloud warehouses and lakehouse tables.

## Quick Start

```bash
cd shared/labs/ch07_data_warehouse_lakehouse
python3 -m pip install -r requirements.txt
python3 starter.py --warehouse-root .warehouse/turanmart
python3 tests/validate_lab.py --warehouse-root .warehouse/turanmart
```

A successful run prints `VALIDATION PASSED`. The generated DuckDB database is written to `.warehouse/turanmart/turanmart_analytics.duckdb`, and CSV exports are written to `.warehouse/turanmart/exports/`.

## Files

| Path | Purpose |
|---|---|
| `data/source_order_lines.csv` | Six deterministic order-line records. |
| `data/source_products.csv` | Four product dimension records. |
| `data/customer_snapshots.csv` | Five customer versions, including two SCD2 versions for `C-1002`. |
| `starter.py` | Builds dimensions, facts, DuckDB tables, and report exports. |
| `tests/validate_lab.py` | Verifies row counts, SCD2 windows, joins, and revenue totals. |
| `expected_output/` | Reference manifest, daily sales summary, and customer history excerpt. |

## Learning Outcomes

After completing the lab, you should be able to explain why dimensional models define a fact-table grain before implementation, how surrogate keys preserve historical joins, and when a curated warehouse mart may later be promoted into an open lakehouse table.

## Cleanup

Delete `.warehouse/` to remove generated database files and exports.
