-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01-create-0003-orders-table.sql
More file actions
22 lines (20 loc) · 874 Bytes
/
01-create-0003-orders-table.sql
File metadata and controls
22 lines (20 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
CREATE TABLE orders
(
id uuid NOT NULL DEFAULT gen_random_uuid(),
customer_id uuid NOT NULL,
product_id uuid NOT NULL,
amount smallint NOT NULL,
created_at timestamp without time zone NOT NULL DEFAULT (current_timestamp AT TIME ZONE 'UTC'),
updated_at timestamp without time zone NOT NULL DEFAULT (current_timestamp AT TIME ZONE 'UTC'),
created_by varchar(256) NOT NULL DEFAULT current_user,
updated_by varchar(256) NOT NULL DEFAULT current_user,
PRIMARY KEY (id),
FOREIGN KEY (customer_id)
REFERENCES customers (id)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (product_id)
REFERENCES products (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);