-- Simplified analytical star schema for Chapter 2.
CREATE TABLE fact_order_line (
    order_line_key BIGINT PRIMARY KEY,
    order_date_key INTEGER NOT NULL,
    customer_key BIGINT NOT NULL,
    product_key BIGINT NOT NULL,
    region_key BIGINT NOT NULL,
    campaign_key BIGINT,
    quantity INTEGER NOT NULL,
    gross_revenue DECIMAL(12, 2) NOT NULL,
    discount_amount DECIMAL(12, 2) DEFAULT 0
);

CREATE TABLE dim_date (
    date_key INTEGER PRIMARY KEY,
    calendar_date DATE NOT NULL,
    month_name TEXT NOT NULL,
    year INTEGER NOT NULL
);

CREATE TABLE dim_customer (
    customer_key BIGINT PRIMARY KEY,
    customer_id TEXT NOT NULL,
    segment TEXT,
    is_current BOOLEAN NOT NULL
);

CREATE TABLE dim_product (
    product_key BIGINT PRIMARY KEY,
    product_id TEXT NOT NULL,
    category TEXT,
    brand TEXT,
    is_current BOOLEAN NOT NULL
);
