-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
51 lines (46 loc) · 1.29 KB
/
Copy pathschema.sql
File metadata and controls
51 lines (46 loc) · 1.29 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
PRAGMA foreign_keys = ON;
DROP TABLE IF EXISTS cart_items;
DROP TABLE IF EXISTS carts;
DROP TABLE IF EXISTS products;
DROP TABLE IF EXISTS users;
CREATE TABLE users (
user_id INTEGER PRIMARY KEY,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
email TEXT NOT NULL,
username TEXT NOT NULL,
role TEXT NOT NULL
);
CREATE TABLE products (
product_id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
category TEXT NOT NULL,
price REAL NOT NULL,
discount_percentage REAL NOT NULL,
rating REAL,
stock INTEGER NOT NULL,
brand TEXT,
availability_status TEXT
);
CREATE TABLE carts (
cart_id INTEGER PRIMARY KEY,
user_id INTEGER NOT NULL,
total REAL NOT NULL,
discounted_total REAL NOT NULL,
total_products INTEGER NOT NULL,
total_quantity INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(user_id)
);
CREATE TABLE cart_items (
cart_item_id INTEGER PRIMARY KEY AUTOINCREMENT,
cart_id INTEGER NOT NULL,
product_id INTEGER NOT NULL,
title TEXT NOT NULL,
price REAL NOT NULL,
quantity INTEGER NOT NULL,
total REAL NOT NULL,
discount_percentage REAL NOT NULL,
discounted_total REAL NOT NULL,
FOREIGN KEY (cart_id) REFERENCES carts(cart_id),
FOREIGN KEY (product_id) REFERENCES products(product_id)
);