This project builds a modern SQL data warehouse using a medallion architecture.
The goal is to consolidate CRM and ERP sales data from CSV files, clean and standardise the data, and create a business-ready analytics model for reporting and analysis.
- Built a three-layer medallion data warehouse in PostgreSQL.
- Loaded CRM and ERP CSV data into source-aligned Bronze tables.
- Cleaned, standardised, deduplicated, and enriched data in the Silver Layer.
- Converted integer-formatted source dates into PostgreSQL
DATEvalues. - Derived product effective dates using window functions.
- Integrated CRM and ERP customer and product data.
- Built customer and product dimensions and a sales fact view.
- Added Silver and Gold data-quality validation scripts.
The warehouse follows a medallion architecture with three layers:
| Layer | Purpose |
|---|---|
| Bronze | Raw source-aligned data |
| Silver | Cleaned and standardised data |
| Gold | Business-ready analytics model |
The gold layer uses a dimensional model designed for analytical queries.
erDiagram
DIM_CUSTOMERS ||--o{ FACT_SALES : "customer_key"
DIM_PRODUCTS ||--o{ FACT_SALES : "product_key"
DIM_CUSTOMERS {
BIGINT customer_key PK
INT customer_id
VARCHAR customer_number
VARCHAR first_name
VARCHAR last_name
VARCHAR country
VARCHAR marital_status
VARCHAR gender
DATE birthdate
DATE create_date
}
DIM_PRODUCTS {
BIGINT product_key PK
INT product_id
VARCHAR product_number
VARCHAR product_name
VARCHAR category_id
VARCHAR category
VARCHAR subcategory
VARCHAR maintenance
INT cost
VARCHAR product_line
DATE start_date
}
FACT_SALES {
VARCHAR order_number
BIGINT product_key FK
BIGINT customer_key FK
DATE order_date
DATE shipping_date
DATE due_date
INT sales_amount
INT quantity
INT price
}
The Gold Layer is implemented via PostgreSQL views. The primary-key and foreign-key labels in the diagram represent logical dimensional relationships rather than physically enforced database constraints.
| Source | Description |
|---|---|
| CRM | Customer, product, and sales transaction data |
| ERP | Customer demographic, location, and product category data |
data-warehouse-project/
│
├── datasets/ # Source CSV files
│
├── docs/ # Project documentation and diagrams
│ ├── data_architecture.png
│ ├── data_catalog.md
│ ├── data_flow.png
│ ├── data_integration.png
│ ├── data_model.png
│ └── naming_conventions.md
│
├── scripts/ # SQL scripts
│ ├── bronze/ # Bronze layer DDL and load scripts
│ ├── silver/ # Silver layer DDL and transformation scripts
│ └── gold/ # Gold layer views / data model scripts
│
├── tests/ # Data quality and validation checks
│
├── README.md
├── LICENSE
└── .gitignore
- Gold Layer Data Catalog
- Naming Conventions
- Bronze Load Procedure
- Silver Transformation Procedure
- Gold Dimensional Model
- Silver Quality Checks
- Gold Quality Checks
- PostgreSQL
- A PostgreSQL role permitted to create databases and schemas
- Permission to use server-side
COPY - Source CSV files available on the PostgreSQL server filesystem
- Run
scripts/00_create_database.sqlwhile connected to an administrative database such aspostgres.- Warning: this script drops and recreates the
data_warehousedatabase.
- Warning: this script drops and recreates the
- Connect to the new
data_warehousedatabase. - Run
scripts/01_create_schemas.sql. - Run
scripts/bronze/02_ddl_bronze.sql. - Run
scripts/bronze/03_proc_load_bronze.sql. - Execute the procedure, passing the absolute dataset directory on the PostgreSQL server:
CALL bronze.load_bronze('/path/to/datasets');- Run
scripts/silver/04_ddl_silver.sql. - Run
scripts/silver/05_proc_load_silver.sql. - Execute:
CALL silver.load_silver();- Run
tests/quality_checks_silver.sql. - Run
scripts/gold/06_ddl_gold.sql. - Run
tests/quality_checks_gold.sql.
Build a SQL data warehouse to consolidate sales data and support analytical reporting and informed decision-making.
- Data Sources: Import CRM and ERP data from CSV files.
- Data Quality: Clean and resolve data quality issues before analysis.
- Integration: Combine both source systems into a single analytics-ready model.
- Scope: Use the latest dataset only; historisation is not required.
- Documentation: Document the architecture, data flow, and final data model.
| Object Type | Pattern | Example |
|---|---|---|
| Schema | <layer> |
bronze, silver, gold |
| Bronze table | <sourcesystem>_<entity> |
crm_cust_info |
| Silver table | <sourcesystem>_<entity> |
crm_cust_info |
| Gold dimension | dim_<entity> |
dim_customers |
| Gold fact | fact_<entity> |
fact_sales |
| Metadata column | dwh_<column_name> |
dwh_create_date |
| Load procedure/script | load_<layer> |
load_bronze |
| Gold aggregate | agg_<entity>_<grain> |
agg_sales_monthly |
Total sales by customer country:
SELECT
c.country,
SUM(f.sales_amount) AS total_sales
FROM gold.fact_sales AS f
JOIN gold.dim_customers AS c
ON f.customer_key = c.customer_key
GROUP BY c.country
ORDER BY total_sales DESC;- SQL
- PostgreSQL
- DBeaver
- GitHub
- Draw.io
- Notion
- Data warehouse design
- Medallion architecture
- SQL development
- Data ingestion from CSV files
- Data cleansing and standardisation
- Data integration
- Dimensional modelling
- Data quality checks
- Technical documentation
- Git-based project organisation
This project is based on a guided SQL data warehouse project by Data with Baraa.
- SQL Data Warehouse from Scratch - Data with Baraa
