-
Notifications
You must be signed in to change notification settings - Fork 0
/
kuberbladeDB.sql
172 lines (148 loc) · 6.15 KB
/
kuberbladeDB.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
drop database if exists kubership;
create database kubership;
use kubership;
create table if not exists owners (
ownerid int primary key auto_increment,
name varchar(64),
contactperson varchar(64),
contactemail varchar(64)
);
create table if not exists users (
userid int primary key auto_increment,
name varchar(64),
email varchar(64),
ownerid int,
foreign key (ownerid) references owners(ownerid)
);
create table if not exists ships
(
shipnr int primary key auto_increment,
name varchar(64),
owner int,
type ENUM('Passenger', 'Cargo'),
image varchar(64),
currentvalue varchar(64),
year DATE
);
create table if not exists planes
(
planenr int primary key auto_increment,
owner int,
type ENUM('Passenger', 'Cargo'),
image varchar(64),
currentvalue varchar(64),
year DATE
);
create table if not exists crewmembers(
crewmemberid int primary key auto_increment,
name varchar(64),
role varchar(64)
);
create table if not exists ships_crewmembers(
id int primary key auto_increment,
ship int,
crewmember int,
foreign key (ship) references ships(shipnr),
foreign key (crewmember) references crewmembers(crewmemberid)
);
create table if not exists planes_crewmembers(
id int primary key auto_increment,
plane int,
crewmember int,
foreign key (plane) references planes(planenr),
foreign key (crewmember) references crewmembers(crewmemberid)
);
CREATE TABLE IF NOT EXISTS shipments
(
shipmentid int primary key auto_increment,
starttime DATE,
endtime DATE,
departurelocation VARCHAR(64),
arrivallocation VARCHAR(64)
);
create table if not exists ships_shipments(
id int primary key auto_increment,
ship int,
shipment int,
foreign key (ship) references ships(shipnr),
foreign key (shipment) references shipments(shipmentid),
unique(ship, shipment)
);
create table if not exists planes_shipments(
id int primary key auto_increment,
planenr int,
shipmentid int,
foreign key (planenr) references planes(planenr),
foreign key (shipmentid) references shipments(shipmentid),
unique (planenr, shipmentid)
);
create table maintenances(
maintenanceid int primary Key auto_increment,
date DATE,
type ENUM('Scheduled','Routine','Emergency'),
description text
);
create table if not exists ships_maintenances(
id int primary key auto_increment,
ship int,
maintenance int,
foreign key (ship) references ships(shipnr),
foreign key (maintenance) references maintenances(maintenanceid),
unique(ship, maintenance)
);
create table if not exists planes_maintenances(
id int primary key auto_increment,
planenr int,
maintenanceid int,
foreign key (planenr) references planes(planenr),
foreign key (maintenanceid) references maintenances(maintenanceid),
unique (planenr,maintenanceid)
);
INSERT INTO owners (name, contactperson, contactemail)
VALUES
('Red-Haired Shanks', 'Shanks', 'shanks@example.com'),
('Monkey D. Dragon', 'Dragon', 'dragon@example.com'),
('Donquixote Doflamingo', 'Doflamingo', 'doflamingo@example.com');
INSERT INTO users (name, email, ownerid)
VALUES
('Luffy', 'luffy@example.com', 1),
('Zoro', 'zoro@example.com', 1),
('Nami', 'nami@example.com', 1),
('Usopp', 'usopp@example.com', 1),
('Chopper', 'chopper@example.com', 2),
('Gol D. Roger', 'gol@example.com', 3),
('Brook', 'brook@example.com', 3);
INSERT INTO ships (shipnr, name, owner, type, image, currentvalue, year)
VALUES
(899,'Thousand Sunny', 1, 'Passenger', 'sunny.jpg', '50', '2010-01-01'),
(900,'Going Merry', 1, 'Passenger', 'merry.jpg', '20', '2000-05-15'),
(901,'Oro Jackson', 2, 'Cargo', 'oro.jpg', '0','2000-05-15'),
(902,'Thriller Bark', 3, 'Passenger', 'thriller.jpg', '2000','2000-05-15');
INSERT INTO crewmembers (name, role)
VALUES
('Monkey D. Luffy', 'Captain'),
('Roronoa Zoro', 'Swordsman'),
('Nami', 'Navigator'),
('Usopp', 'Sniper'),
('Tony Tony Chopper', 'Doctor'),
('Gol D. Roger', 'Captain'),
('Brook', 'Musician');
insert into ships_crewmembers(ship, crewmember)
values (899,1),(899,2),(902,3),(899,4),(900,5);
INSERT INTO shipments (starttime, endtime, departurelocation, arrivallocation)
VALUES
('2022-01-01', '2022-01-15', 'Fish-Man Island', 'Sabaody Archipelago'),
('2024-01-01', '2022-01-15', 'Dress Rosa', 'Wano Kuni'),
('2005-03-10', '2005-04-20', 'East Blue', 'Alabasta'),
('2005-03-10', '2005-04-20', 'Water 7', 'Enies Lobby'),
('2015-06-01', '2015-07-15', 'Florian Triangle', 'Sabaody Archipelago');
insert into ships_shipments (ship, shipment)
values (899,1),(900,2);
INSERT INTO maintenances (date, type, description)
VALUES
('2022-02-01', 'Scheduled', 'Thousand Sunny underwent a major engine overhaul.'),
('2004-05-01', 'Emergency', 'Going Merry last repairs'),
('2005-05-01', 'Emergency', 'Going Merry underwent extensive repairs at Water 7.'),
('2015-08-01', 'Routine', 'Thriller Bark received routine maintenance and repairs.');
insert into ships_maintenances (ship, maintenance)
values (899, 1),(900, 2),(900, 3),(902, 4);