first
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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);
|
||||
Reference in New Issue
Block a user