-
Notifications
You must be signed in to change notification settings - Fork 0
/
Create_tables_rideshare.sql
68 lines (58 loc) · 2.39 KB
/
Create_tables_rideshare.sql
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
--- Create table scripts
CREATE TABLE IF NOT EXISTS Riders (
riderId INT AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(255) NOT NULL,
lastname VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
mobile VARCHAR(255) NOT NULL,
createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=INNODB;
ALTER TABLE RIDERS ADD COLUMN score INTEGER;
CREATE TABLE IF NOT EXISTS RiderPreferences (
riderId INT PRIMARY KEY,
tollRoadPreferred BOOL NOT NULL DEFAULT 0,
shortDurationPreferred BOOL NOT NULL DEFAULT 0,
createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (riderId) REFERENCES Riders(riderId)
) ENGINE=INNODB;
-- if the constraint has to be dropped, name the constraint
ALTER TABLE RiderPreferences DROP CONSTRAINT riderpreferences_ibfk_1;
-- DELETE CASCADE will delete the child records if the parent record is deleted.
ALTER TABLE RiderPreferences
ADD CONSTRAINT riderpreferences_ibfk_1 FOREIGN KEY (riderId)
REFERENCES Riders(riderId)
ON DELETE CASCADE;
CREATE TABLE IF NOT EXISTS AppPartners (
appPartnerId INT AUTO_INCREMENT PRIMARY KEY,
appPartnerName VARCHAR(255) NOT NULL,
isGlobalAppPartner BOOL NOT NULL DEFAULT 0,
revenueSharing BOOL NOT NULL DEFAULT 0,
revenueSharePercentage INT DEFAULT 0,
createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
CHECK (revenueSharePercentage <= 50)
) ENGINE=INNODB;
CREATE TABLE IF NOT EXISTS Products (
productId INT AUTO_INCREMENT PRIMARY KEY,
productName VARCHAR(255) NOT NULL UNIQUE,
capacity INT NOT NULL,
basePrice DECIMAL(10, 2) NOT NULL,
minimumPrice DECIMAL(10, 2) NOT NULL,
costPerMinute DECIMAL(10, 2) NOT NULL,
costPerDistance DECIMAL(10, 2) NOT NULL,
serviceFees DECIMAL(10, 2) NOT NULL,
createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=INNODB;
CREATE TABLE IF NOT EXISTS ProductAppPartners (
productId INT,
appPartnerId INT,
createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (productId, appPartnerId),
FOREIGN KEY (productId) REFERENCES Products(productId),
FOREIGN KEY (appPartnerId) REFERENCES AppPartners(appPartnerId)
) ENGINE=INNODB;
-- End of create table scripts