Files
template-vitrine/backend/migrations/000010_create_orders.up.sql
T
2026-09-14 20:50:19 +02:00

28 lines
1.1 KiB
SQL

CREATE TABLE orders (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
customer_name TEXT NOT NULL,
customer_email TEXT NOT NULL,
customer_phone TEXT NOT NULL DEFAULT '',
status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'confirmed', 'preparing', 'shipped', 'completed', 'cancelled')),
total_cents BIGINT NOT NULL DEFAULT 0,
notes TEXT NOT NULL DEFAULT '',
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE order_items (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
order_id UUID NOT NULL REFERENCES orders(id) ON DELETE CASCADE,
product_id UUID REFERENCES products(id) ON DELETE SET NULL,
product_name TEXT NOT NULL,
price_tier_id UUID REFERENCES price_tiers(id) ON DELETE SET NULL,
unit_symbol TEXT NOT NULL,
tier_quantity NUMERIC(14, 3) NOT NULL,
multiplier BIGINT NOT NULL DEFAULT 1,
unit_price_cents BIGINT NOT NULL,
total_cents BIGINT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_order_items_order_id ON order_items(order_id);