Skip to main content

max / makenotwork

488 B · 11 lines History Blame Raw
1 -- Shopping cart: persistent across sessions/devices, one row per item per user.
2 -- Mirrors the wishlists table structure (composite PK, CASCADE deletes).
3 CREATE TABLE IF NOT EXISTS cart_items (
4 user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
5 item_id UUID NOT NULL REFERENCES items(id) ON DELETE CASCADE,
6 created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
7 PRIMARY KEY (user_id, item_id)
8 );
9
10 CREATE INDEX IF NOT EXISTS idx_cart_items_item ON cart_items(item_id);
11