-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
68 lines (62 loc) · 1.7 KB
/
schema.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
CREATE TABLE journeys (
journey_id TEXT PRIMARY KEY,
search_id TEXT,
n_legs INTEGER,
cabin_baggage INTEGER,
checked_baggage INTEGER,
class TEXT,
airline TEXT,
FOREIGN KEY(search_id) REFERENCES flight_searches(search_id)
);
CREATE TABLE legs (
leg_id TEXT PRIMARY KEY,
journey_id TEXT,
leg_number INTEGER,
departure_time TEXT,
arrival_time TEXT,
departure_airport TEXT,
arrival_airport TEXT,
duration INTEGER,
n_stops INTEGER,
stopover_airports TEXT,
distance_nominal INTEGER,
distance_absolute INTEGER,
FOREIGN KEY(journey_id) REFERENCES journeys(journey_id)
);
CREATE TABLE prices (
price_id INTEGER PRIMARY KEY AUTOINCREMENT,
journey_id TEXT,
price REAL,
currency TEXT,
created_at TIMESTAMP,
FOREIGN KEY(journey_id) REFERENCES journeys(journey_id)
);
CREATE TABLE flight_searches (
search_id TEXT PRIMARY KEY,
journey_type TEXT,
origin TEXT,
destination TEXT,
leave_date TEXT,
return_date TEXT,
flex INTEGER
);
CREATE TABLE searches_journeys_prices (
search_id INTEGER,
journey_id INTEGER,
price_id INTEGER,
PRIMARY KEY(search_id, journey_id, price_id),
FOREIGN KEY(search_id) REFERENCES flight_searches(search_id),
FOREIGN KEY(journey_id) REFERENCES journeys(journey_id),
FOREIGN KEY(price_id) REFERENCES prices(price_id)
);
CREATE TABLE journeys_prices (
journey_id INTEGER,
price_id INTEGER,
PRIMARY KEY(journey_id, price_id),
FOREIGN KEY(journey_id) REFERENCES journeys(journey_id),
FOREIGN KEY(price_id) REFERENCES prices(price_id)
);
CREATE TABLE compound_airport_codes (
compound_code TEXT PRIMARY KEY,
included_airport_code TEXT
);