-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorders.sql
More file actions
37 lines (26 loc) · 874 Bytes
/
orders.sql
File metadata and controls
37 lines (26 loc) · 874 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
35
36
37
--
-- Name: orders; Type: TABLE; Schema: -; Owner: -
--
CREATE TABLE IF NOT EXISTS orders (
id integer PRIMARY KEY,
user_id integer NOT NULL REFERENCES users(id),
status text DEFAULT 'pending' NOT NULL CHECK (status IN ('pending', 'completed'))
);
COMMENT ON TABLE orders IS 'Customer orders';
COMMENT ON COLUMN orders.user_id IS 'Reference to user';
--
-- Name: idx_orders_status; Type: INDEX; Schema: -; Owner: -
--
CREATE INDEX IF NOT EXISTS idx_orders_status ON orders (status);
--
-- Name: idx_orders_user_id; Type: INDEX; Schema: -; Owner: -
--
CREATE INDEX IF NOT EXISTS idx_orders_user_id ON orders (user_id);
--
-- Name: orders; Type: RLS; Schema: -; Owner: -
--
ALTER TABLE orders ENABLE ROW LEVEL SECURITY;
--
-- Name: orders_policy; Type: POLICY; Schema: -; Owner: -
--
CREATE POLICY orders_policy ON orders TO PUBLIC USING (user_id = 1);