-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
60 lines (49 loc) · 1.66 KB
/
schema.sql
File metadata and controls
60 lines (49 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
DROP TABLE IF EXISTS fct_payment;
DROP TABLE IF EXISTS fct_order_item;
DROP TABLE IF EXISTS fct_order;
DROP TABLE IF EXISTS dim_product;
DROP TABLE IF EXISTS dim_customer;
CREATE TABLE dim_customer (
customer_id INT PRIMARY KEY,
full_name TEXT NOT NULL,
email TEXT,
created_at TIMESTAMP NOT NULL,
country TEXT
);
CREATE TABLE dim_product (
product_id INT PRIMARY KEY,
product_name TEXT NOT NULL,
category TEXT NOT NULL,
unit_price NUMERIC(12,2) NOT NULL,
is_active BOOLEAN NOT NULL DEFAULT TRUE
);
CREATE TABLE fct_order (
order_id INT PRIMARY KEY,
customer_id INT NOT NULL REFERENCES dim_customer(customer_id),
order_ts TIMESTAMP NOT NULL,
order_status TEXT NOT NULL,
channel TEXT NOT NULL
);
CREATE TABLE fct_order_item (
order_id INT NOT NULL REFERENCES fct_order(order_id),
product_id INT NOT NULL REFERENCES dim_product(product_id),
quantity INT NOT NULL CHECK (quantity > 0),
unit_price NUMERIC(12,2) NOT NULL,
PRIMARY KEY (order_id, product_id)
);
CREATE TABLE fct_payment (
payment_id INT PRIMARY KEY,
order_id INT NOT NULL REFERENCES fct_order(order_id),
paid_ts TIMESTAMP,
amount NUMERIC(12,2) NOT NULL,
payment_method TEXT NOT NULL,
payment_status TEXT NOT NULL
);
-- Data Quality results table (PASS/FAIL per check, per run)
CREATE TABLE IF NOT EXISTS dq_results (
dq_check_name TEXT NOT NULL,
status TEXT NOT NULL CHECK (status IN ('PASS', 'FAIL')),
failed_rows INT NOT NULL,
run_ts TIMESTAMP NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_dq_results_run_ts ON dq_results (run_ts DESC);