forked from BlinkTagInc/gtfs-to-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtfs_to_mysql.sql
135 lines (105 loc) · 3.45 KB
/
gtfs_to_mysql.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
USE gtfs_for_import;
DROP TABLE IF EXISTS agency;
CREATE TABLE `agency` (
agency_id int(11) PRIMARY KEY,
agency_name VARCHAR(255),
agency_url VARCHAR(255),
agency_timezone VARCHAR(50),
agency_phone VARCHAR(50)
);
DROP TABLE IF EXISTS calendar;
CREATE TABLE `calendar` (
service_id INT(11),
monday TINYINT(1),
tuesday TINYINT(1),
wednesday TINYINT(1),
thursday TINYINT(1),
friday TINYINT(1),
saturday TINYINT(1),
sunday TINYINT(1),
start_date VARCHAR(8),
end_date VARCHAR(8),
KEY `service_id` (service_id)
);
DROP TABLE IF EXISTS calendar_dates;
CREATE TABLE `calendar_dates` (
service_id INT(11),
`date` VARCHAR(8),
exception_type INT(2),
KEY `service_id` (service_id),
KEY `exception_type` (exception_type)
);
DROP TABLE IF EXISTS fare_attributes;
CREATE TABLE `fare_attributes` (
fare_id INT(11),
price DECIMAL(9,6),
currency_type VARCHAR(8),
payment_method INT(11),
transfers INT(11),
KEY `fare_id` (fare_id)
);
DROP TABLE IF EXISTS fare_rules;
CREATE TABLE `fare_rules` (
fare_id INT(11),
route_id INT(11),
KEY `fare_id` (fare_id),
KEY `route_id` (route_id)
);
DROP TABLE IF EXISTS routes;
CREATE TABLE `routes` (
route_id INT(11) PRIMARY KEY,
route_short_name VARCHAR(50),
route_long_name VARCHAR(255),
route_type INT(2),
KEY `route_type` (route_type)
);
DROP TABLE IF EXISTS shapes;
CREATE TABLE `shapes` (
shape_id VARCHAR(50),
shape_pt_lat DECIMAL(9,6),
shape_pt_lon DECIMAL(9,6),
shape_pt_sequence INT(11),
KEY `shape_id` (shape_id)
);
DROP TABLE IF EXISTS stop_times;
CREATE TABLE `stop_times` (
trip_id INT(11),
arrival_time VARCHAR(8),
departure_time VARCHAR(8),
stop_id INT(11),
stop_sequence INT(11),
KEY `trip_id` (trip_id),
KEY `stop_id` (stop_id),
KEY `stop_sequence` (stop_sequence)
);
DROP TABLE IF EXISTS stops;
CREATE TABLE `stops` (
stop_id INT(11) PRIMARY KEY,
stop_name VARCHAR(255),
stop_lat DECIMAL(9,6),
stop_lon DECIMAL(9,6),
KEY `stop_lat` (stop_lat),
KEY `stop_lon` (stop_lon)
);
DROP TABLE IF EXISTS trips;
CREATE TABLE `trips` (
route_id INT(11),
service_id INT(11),
trip_id INT(11) PRIMARY KEY,
trip_headsign VARCHAR(255),
direction_id TINYINT(1),
shape_id VARCHAR(50),
KEY `route_id` (route_id),
KEY `service_id` (service_id),
KEY `direction_id` (direction_id),
KEY `shape_id` (shape_id)
);
LOAD DATA LOCAL INFILE 'agency.txt' INTO TABLE agency FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' IGNORE 1 LINES;
LOAD DATA LOCAL INFILE 'calendar.txt' INTO TABLE calendar FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' IGNORE 1 LINES;
LOAD DATA LOCAL INFILE 'calendar_dates.txt' INTO TABLE calendar_dates FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' IGNORE 1 LINES;
LOAD DATA LOCAL INFILE 'fare_attributes.txt' INTO TABLE fare_attributes FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' IGNORE 1 LINES;
LOAD DATA LOCAL INFILE 'fare_rules.txt' INTO TABLE fare_rules FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' IGNORE 1 LINES;
LOAD DATA LOCAL INFILE 'routes.txt' INTO TABLE routes FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' IGNORE 1 LINES;
LOAD DATA LOCAL INFILE 'stop_times.txt' INTO TABLE stop_times FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' IGNORE 1 LINES;
LOAD DATA LOCAL INFILE 'stops.txt' INTO TABLE stops FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' IGNORE 1 LINES;
LOAD DATA LOCAL INFILE 'trips.txt' INTO TABLE trips FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' IGNORE 1 LINES;