· 5 years ago · Apr 06, 2020, 07:14 PM
1CREATE TABLE IF NOT EXISTS orders
2(
3 id BIGSERIAL PRIMARY KEY,
4 user_id BIGINT REFERENCES users (id) NOT NULL,
5 created_at DATE NOT NULL
6);
7CREATE TABLE IF NOT EXISTS order_entries
8(
9 product_id BIGINT REFERENCES products (id) NOT NULL,
10 order_id BIGINT REFERENCES orders (id) NOT NULL,
11 product_quantity BIGINT NOT NULL,
12 price NUMERIC(15, 2) NOT NULL,
13 total NUMERIC(15, 2) NOT NULL
14);
15CREATE TABLE IF NOT EXISTS carts
16(
17 id BIGSERIAL PRIMARY KEY,
18 product_id BIGINT REFERENCES products (id) NOT NULL,
19 product_quantity BIGINT NOT NULL,
20 user_id BIGINT REFERENCES users (id) NOT NULL
21);