-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcreate_order_items_table.sql
More file actions
34 lines (30 loc) · 997 Bytes
/
create_order_items_table.sql
File metadata and controls
34 lines (30 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
-- Create order_items table for Electrium Store
-- Run this in your Supabase SQL Editor
DROP TABLE IF EXISTS order_items;
CREATE TABLE order_items (
item_id SERIAL PRIMARY KEY,
order_id INTEGER REFERENCES orders(order_id) ON DELETE CASCADE,
product_id INTEGER REFERENCES products(id),
quantity INTEGER NOT NULL,
unit_price DECIMAL(10,2) NOT NULL,
order_type TEXT NOT NULL -- 'rent' or 'sell'
);
-- Enable Row Level Security
ALTER TABLE order_items ENABLE ROW LEVEL SECURITY;
-- Create policies for order_items table
CREATE POLICY "Users can view own order items" ON order_items
FOR SELECT USING (
EXISTS (
SELECT 1 FROM orders
WHERE orders.order_id = order_items.order_id
AND orders.customer_id = auth.uid()
)
);
CREATE POLICY "Users can insert own order items" ON order_items
FOR INSERT WITH CHECK (
EXISTS (
SELECT 1 FROM orders
WHERE orders.order_id = order_items.order_id
AND orders.customer_id = auth.uid()
)
);