-
Notifications
You must be signed in to change notification settings - Fork 5
/
db_create_v3.psql
741 lines (469 loc) · 17.1 KB
/
db_create_v3.psql
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
--
-- PostgreSQL database cluster dump
--
SET default_transaction_read_only = off;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
--
-- Drop databases
--
DROP DATABASE "PlaneReports";
--
-- Drop roles
--
DROP ROLE planereportupdater;
DROP ROLE postgres;
--
-- Roles
--
CREATE ROLE planereportupdater;
ALTER ROLE planereportupdater WITH NOSUPERUSER INHERIT NOCREATEROLE NOCREATEDB LOGIN NOREPLICATION NOBYPASSRLS PASSWORD 'md5879655fbe580296526dcb025d47d4216';
CREATE ROLE postgres;
ALTER ROLE postgres WITH SUPERUSER INHERIT CREATEROLE CREATEDB LOGIN REPLICATION BYPASSRLS;
--
-- Database creation
--
CREATE DATABASE "PlaneReports" WITH TEMPLATE = template0 OWNER = postgres;
REVOKE CONNECT,TEMPORARY ON DATABASE template1 FROM PUBLIC;
GRANT CONNECT ON DATABASE template1 TO PUBLIC;
\connect "PlaneReports"
SET default_transaction_read_only = off;
--
-- PostgreSQL database dump
--
-- Dumped from database version 9.6.8
-- Dumped by pg_dump version 9.6.8
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: DATABASE "PlaneReports"; Type: COMMENT; Schema: -; Owner: postgres
--
COMMENT ON DATABASE "PlaneReports" IS 'This will be used to store position reports from aircraft, details of airports that are within range, and details of reporting instances of dump1090';
--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
--
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
--
-- Name: postgis; Type: EXTENSION; Schema: -; Owner:
--
CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public;
--
-- Name: EXTENSION postgis; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION postgis IS 'PostGIS geometry, geography, and raster spatial types and functions';
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: airport; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.airport (
icao character(4),
iata character(3),
name character varying(50),
city character varying(50),
country character varying(50),
altitude integer,
location public.geography(Point,4326)
);
ALTER TABLE public.airport OWNER TO postgres;
--
-- Name: COLUMN airport.icao; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.airport.icao IS '4 Letter code that uniquely identifies an airport';
--
-- Name: COLUMN airport.iata; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.airport.iata IS 'Old-fashioned 3 letter code that was used to identify airports';
--
-- Name: COLUMN airport.name; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.airport.name IS 'Name of the airport (e.g. Sydney International)';
--
-- Name: COLUMN airport.city; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.airport.city IS 'City the airport is located in';
--
-- Name: COLUMN airport.country; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.airport.country IS 'Country airport is in';
--
-- Name: COLUMN airport.altitude; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.airport.altitude IS 'Height of airport';
--
-- Name: COLUMN airport.location; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.airport.location IS 'A point containing the latitude longitude of the airport';
--
-- Name: airport_daily_events; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.airport_daily_events (
hex character(6),
flight character(8),
type_of_event character(1),
airport character(4),
event_epoch integer,
runway character varying(20)
);
ALTER TABLE public.airport_daily_events OWNER TO postgres;
--
-- Name: TABLE airport_daily_events; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON TABLE public.airport_daily_events IS 'What planes have had events at this airport today';
--
-- Name: COLUMN airport_daily_events.hex; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.airport_daily_events.hex IS 'ICAO 24 code of plane involved';
--
-- Name: COLUMN airport_daily_events.flight; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.airport_daily_events.flight IS 'The flight that the plane was calling itself at the time.';
--
-- Name: COLUMN airport_daily_events.type_of_event; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.airport_daily_events.type_of_event IS 'Type of event "L" landing, "T" takeoff, "B" bump and go "?" unknown';
--
-- Name: COLUMN airport_daily_events.airport; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.airport_daily_events.airport IS 'Airport event occured at';
--
-- Name: daily_flights_seen; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.daily_flights_seen (
date_seen date NOT NULL,
flight character(8),
reporter character(10) NOT NULL,
time_first_seen integer,
time_last_seen integer
);
ALTER TABLE public.daily_flights_seen OWNER TO postgres;
--
-- Name: daily_planes_seen; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.daily_planes_seen (
date_seen date NOT NULL,
hex character(6) NOT NULL,
reporter character(10) NOT NULL,
time_first_seen integer,
time_last_seen integer
);
ALTER TABLE public.daily_planes_seen OWNER TO postgres;
--
-- Name: TABLE daily_planes_seen; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON TABLE public.daily_planes_seen IS 'What planes we have seen today';
--
-- Name: COLUMN daily_planes_seen.hex; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.daily_planes_seen.hex IS 'ICAO24 code of the plane seen';
--
-- Name: daily_stats; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.daily_stats (
record_date date NOT NULL,
max_dist double precision,
max_dist_hex character(6),
max_dist_flight character(8),
max_alt double precision,
number_reports integer,
number_planes integer,
max_time_epoch integer,
reporter character(10),
max_dist_loc public.geography(Point,4326)
);
ALTER TABLE public.daily_stats OWNER TO postgres;
--
-- Name: TABLE daily_stats; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON TABLE public.daily_stats IS 'Where we accumulate the max etc that we''ve seen';
--
-- Name: COLUMN daily_stats.record_date; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.daily_stats.record_date IS 'Day of these records';
--
-- Name: COLUMN daily_stats.max_dist_hex; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.daily_stats.max_dist_hex IS 'ICAO24 code of the plane that had the max distance';
--
-- Name: COLUMN daily_stats.max_dist_flight; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.daily_stats.max_dist_flight IS 'Flight the plane was going under when it set the day''s record';
--
-- Name: COLUMN daily_stats.max_alt; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.daily_stats.max_alt IS 'Max Altitude seen - not recording plane(s) as there may be many of them';
--
-- Name: COLUMN daily_stats.number_reports; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.daily_stats.number_reports IS 'Number of plane reports recorded today';
--
-- Name: COLUMN daily_stats.number_planes; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.daily_stats.number_planes IS 'Number of distinct planes seen today';
--
-- Name: COLUMN daily_stats.max_time_epoch; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.daily_stats.max_time_epoch IS 'The time at which this distance was recorded (seconds since epoch)';
--
-- Name: planereports; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.planereports (
hex character(6),
squawk character(6),
flight character(8),
"isMetric" boolean,
"isMLAT" boolean,
altitude double precision,
speed double precision,
vert_rate double precision,
bearing integer,
messages_sent integer,
report_location public.geography(Point,4326),
report_epoch integer,
reporter character(10),
rssi double precision,
nucp integer,
isgnd boolean
);
ALTER TABLE public.planereports OWNER TO postgres;
--
-- Name: TABLE planereports; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON TABLE public.planereports IS 'Reports of a plane''s position.';
--
-- Name: COLUMN planereports.hex; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.planereports.hex IS 'ICAO24 code that uniquely identifies aircraft.';
--
-- Name: COLUMN planereports.squawk; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.planereports.squawk IS 'Code used by local air traffic controllers to communicate with the planes they are controllong.';
--
-- Name: COLUMN planereports.flight; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.planereports.flight IS 'Flight number assigned to aircraft for this particular route/time';
--
-- Name: COLUMN planereports."isMetric"; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.planereports."isMetric" IS 'Does this record have metric units (metres/kmh) for altitude & speed';
--
-- Name: COLUMN planereports."isMLAT"; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.planereports."isMLAT" IS 'Was this position report derived from multilateration';
--
-- Name: COLUMN planereports.altitude; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.planereports.altitude IS 'Height of aircraft';
--
-- Name: COLUMN planereports.speed; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.planereports.speed IS 'Speed of aircraft';
--
-- Name: COLUMN planereports.vert_rate; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.planereports.vert_rate IS 'Rate of descent/ascent in metres/feet per minute';
--
-- Name: COLUMN planereports.bearing; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.planereports.bearing IS 'Direction aircraft is heading';
--
-- Name: COLUMN planereports.messages_sent; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.planereports.messages_sent IS 'Number of messages received from this aircraft at the time of this report';
--
-- Name: COLUMN planereports.report_location; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.planereports.report_location IS 'Encoded lat/lon of report (for use in postgis functions)';
--
-- Name: COLUMN planereports.report_epoch; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON COLUMN public.planereports.report_epoch IS 'Timestamp of report as seconds from epoch.';
--
-- Name: reporter; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.reporter (
name character(10),
type character(10),
reporter_location public.geography(Point,4326),
url character varying(256)
);
ALTER TABLE public.reporter OWNER TO postgres;
--
-- Name: runways; Type: TABLE; Schema: public; Owner: planereportupdater
--
CREATE TABLE public.runways (
airport character(4),
name character varying(20),
runway_area public.geography(Polygon,4326),
heading real,
location public.geography(Point,4326)
);
ALTER TABLE public.runways OWNER TO planereportupdater;
--
-- Name: daily_stats date; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.daily_stats
ADD CONSTRAINT date PRIMARY KEY (record_date);
--
-- Name: daily_stats date_rep; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.daily_stats
ADD CONSTRAINT date_rep UNIQUE (record_date, reporter);
--
-- Name: daily_flights_seen flight_date_rep; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.daily_flights_seen
ADD CONSTRAINT flight_date_rep UNIQUE (date_seen, flight, reporter);
--
-- Name: airport_daily_events hex_air_epoch; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.airport_daily_events
ADD CONSTRAINT hex_air_epoch UNIQUE (hex, airport, event_epoch);
--
-- Name: daily_planes_seen hex_date_rep; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.daily_planes_seen
ADD CONSTRAINT hex_date_rep UNIQUE (date_seen, hex, reporter);
--
-- Name: runways runway_uniq; Type: CONSTRAINT; Schema: public; Owner: planereportupdater
--
ALTER TABLE ONLY public.runways
ADD CONSTRAINT runway_uniq UNIQUE (airport, name);
--
-- Name: reporter uniq_reporter; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.reporter
ADD CONSTRAINT uniq_reporter UNIQUE (name);
--
-- Name: airport unique_icao; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.airport
ADD CONSTRAINT unique_icao UNIQUE (icao);
--
-- Name: ade_hex_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX ade_hex_idx ON public.airport_daily_events USING btree (hex);
--
-- Name: ev_epoch; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX ev_epoch ON public.airport_daily_events USING btree (event_epoch);
--
-- Name: hex_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX hex_idx ON public.planereports USING btree (hex);
--
-- Name: pr_epoch; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX pr_epoch ON public.planereports USING btree (report_epoch);
--
-- Name: rep_loc; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX rep_loc ON public.planereports USING gist (report_location);
--
-- Name: TABLE airport; Type: ACL; Schema: public; Owner: postgres
--
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.airport TO planereportupdater;
--
-- Name: TABLE airport_daily_events; Type: ACL; Schema: public; Owner: postgres
--
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.airport_daily_events TO PUBLIC;
--
-- Name: TABLE daily_flights_seen; Type: ACL; Schema: public; Owner: postgres
--
GRANT SELECT,INSERT,UPDATE ON TABLE public.daily_flights_seen TO planereportupdater;
--
-- Name: TABLE daily_planes_seen; Type: ACL; Schema: public; Owner: postgres
--
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.daily_planes_seen TO PUBLIC;
--
-- Name: TABLE daily_stats; Type: ACL; Schema: public; Owner: postgres
--
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.daily_stats TO PUBLIC;
GRANT SELECT,INSERT,UPDATE ON TABLE public.daily_stats TO planereportupdater;
--
-- Name: TABLE planereports; Type: ACL; Schema: public; Owner: postgres
--
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.planereports TO planereportupdater;
--
-- Name: TABLE reporter; Type: ACL; Schema: public; Owner: postgres
--
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.reporter TO planereportupdater;
--
-- PostgreSQL database dump complete
--
\connect postgres
SET default_transaction_read_only = off;
--
-- PostgreSQL database dump
--
-- Dumped from database version 9.6.8
-- Dumped by pg_dump version 9.6.8
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: DATABASE postgres; Type: COMMENT; Schema: -; Owner: postgres
--
COMMENT ON DATABASE postgres IS 'default administrative connection database';
--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
--
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
--
-- PostgreSQL database dump complete
--
\connect template1
SET default_transaction_read_only = off;
--
-- PostgreSQL database dump
--
-- Dumped from database version 9.6.8
-- Dumped by pg_dump version 9.6.8
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: DATABASE template1; Type: COMMENT; Schema: -; Owner: postgres
--
COMMENT ON DATABASE template1 IS 'default template for new databases';
--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
--
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
--
-- PostgreSQL database dump complete
--
--
-- PostgreSQL database cluster dump complete
--