examples/storefront Public
-- Orders: a checked-out cart, its address and what it costs. Lines copy the name and price at-- checkout, so later catalog edits do not change past orders.CREATE TABLE orders ( id TEXT PRIMARY KEY, cart_id TEXT NOT NULL UNIQUE REFERENCES carts (id), status TEXT NOT NULL DEFAULT 'pending_payment' CHECK (status IN ('pending_payment', 'paid', 'cancelled', 'fulfilled')), email TEXT NOT NULL, ship_to TEXT NOT NULL, -- JSON: name, line1, line2, city, postal_code, country subtotal_cents INTEGER NOT NULL, shipping_cents INTEGER NOT NULL, total_cents INTEGER NOT NULL, currency TEXT NOT NULL, payment_intent_id TEXT UNIQUE, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL);CREATE INDEX orders_by_status ON orders (status, created_at);CREATE TABLE order_items ( order_id TEXT NOT NULL REFERENCES orders (id) ON DELETE CASCADE, product_id TEXT NOT NULL REFERENCES products (id), name TEXT NOT NULL, quantity INTEGER NOT NULL CHECK (quantity > 0), unit_price_cents INTEGER NOT NULL, PRIMARY KEY (order_id, product_id));