forked from cbmsc-diti/mogi-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcopcast-db.sql
694 lines (487 loc) · 15 KB
/
copcast-db.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
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
--
-- PostgreSQL database dump
--
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
--
-- 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';
SET search_path = public, pg_catalog;
--
-- Name: archive_registration(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION archive_registration() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
INSERT INTO registrations_history SELECT NEW.*;
RETURN NULL;
END;
$$;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: SequelizeMeta; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE "SequelizeMeta" (
name character varying(255) NOT NULL
);
--
-- Name: SequelizeMetaBackup; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE "SequelizeMetaBackup" (
id integer NOT NULL,
"from" character varying(255),
"to" character varying(255)
);
--
-- Name: SequelizeMeta_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE "SequelizeMeta_id_seq"
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: SequelizeMeta_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE "SequelizeMeta_id_seq" OWNED BY "SequelizeMetaBackup".id;
--
-- Name: access_tokens; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE access_tokens (
id uuid NOT NULL,
scope character varying(255) NOT NULL,
"expirationDate" timestamp with time zone,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"userId" bigint NOT NULL
);
--
-- Name: batteries; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE batteries (
id integer NOT NULL,
date timestamp with time zone NOT NULL,
"batteryPercentage" double precision NOT NULL,
"batteryHealth" integer NOT NULL,
plugged integer,
temperature integer,
"userId" bigint NOT NULL
);
--
-- Name: batteries_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE batteries_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: batteries_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE batteries_id_seq OWNED BY batteries.id;
--
-- Name: exports; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE exports (
id integer NOT NULL,
"exporterId" integer NOT NULL,
"recorderId" integer NOT NULL,
"initialDate" timestamp with time zone NOT NULL,
"finalDate" timestamp with time zone NOT NULL,
"expireDate" timestamp with time zone,
status character varying(255),
filepath character varying(255),
filehash character varying(255),
"createdAt" timestamp with time zone,
"updatedAt" timestamp with time zone
);
--
-- Name: exports_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE exports_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: exports_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE exports_id_seq OWNED BY exports.id;
--
-- Name: groups; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE groups (
id integer NOT NULL,
name character varying(255) NOT NULL,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"isAdmin" boolean,
lat double precision,
lng double precision
);
--
-- Name: groups_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE groups_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: groups_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE groups_id_seq OWNED BY groups.id;
--
-- Name: histories; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE histories (
id integer NOT NULL,
"previousState" character varying(255),
"nextState" character varying(255),
"userId" bigint,
date timestamp with time zone,
extras text
);
--
-- Name: histories_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE histories_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: histories_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE histories_id_seq OWNED BY histories.id;
--
-- Name: incidentForms; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE "incidentForms" (
id integer NOT NULL,
date timestamp with time zone,
address character varying(255),
lat double precision,
lng double precision,
accident boolean,
gravity integer,
injured integer,
fine boolean,
"fineType" character varying(255),
arrest boolean,
resistance boolean,
argument boolean,
"useOfForce" boolean,
"useLethalForce" boolean,
"userId" bigint NOT NULL,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL
);
--
-- Name: incidentForms_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE "incidentForms_id_seq"
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: incidentForms_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE "incidentForms_id_seq" OWNED BY "incidentForms".id;
--
-- Name: incidents; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE incidents (
id integer NOT NULL,
date timestamp with time zone NOT NULL,
"userId" bigint NOT NULL,
lat double precision NOT NULL,
lng double precision NOT NULL
);
--
-- Name: incidents_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE incidents_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: incidents_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE incidents_id_seq OWNED BY incidents.id;
--
-- Name: locations; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE locations (
id integer NOT NULL,
date timestamp with time zone NOT NULL,
lat double precision NOT NULL,
lng double precision NOT NULL,
"userId" bigint NOT NULL,
accuracy double precision,
satellites integer,
provider character varying(255),
bearing double precision,
speed double precision
);
--
-- Name: locations_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE locations_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: locations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE locations_id_seq OWNED BY locations.id;
--
-- Name: registrations; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE registrations (
imei character varying(32) NOT NULL,
simid character varying(32) NOT NULL,
public_key character varying(1024) NOT NULL,
"createdAt" timestamp with time zone NOT NULL,
username character varying(255) NOT NULL,
ipaddress character varying(48) NOT NULL
);
--
-- Name: registrations_history; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE registrations_history (
imei character varying(32) NOT NULL,
simid character varying(32) NOT NULL,
public_key character varying(1024) NOT NULL,
"createdAt" timestamp with time zone NOT NULL,
username character varying(255) NOT NULL,
ipaddress character varying(48) NOT NULL
);
--
-- Name: users; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE users (
id bigint NOT NULL,
username character varying(255) NOT NULL,
"passwordHash" character varying(1024) NOT NULL,
"passwordSalt" character varying(1024) NOT NULL,
name character varying(255) NOT NULL,
email character varying(255) NOT NULL,
"gcmRegistration" character varying(1024),
"isAdmin" boolean DEFAULT false NOT NULL,
"lastLat" double precision,
"lastLng" double precision,
"lastLocationUpdateDate" timestamp with time zone,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"groupId" integer,
"profilePicture" character varying(255),
language character varying(5),
"rememberToken" character varying(255),
"isEnabled" boolean DEFAULT true,
role character varying(20)
);
--
-- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE users_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE users_id_seq OWNED BY users.id;
--
-- Name: videos; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE videos (
id uuid NOT NULL,
date timestamp with time zone NOT NULL,
duration integer NOT NULL,
"userId" bigint NOT NULL,
"isValid" boolean,
filesize integer NOT NULL
);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY "SequelizeMetaBackup" ALTER COLUMN id SET DEFAULT nextval('"SequelizeMeta_id_seq"'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY batteries ALTER COLUMN id SET DEFAULT nextval('batteries_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY exports ALTER COLUMN id SET DEFAULT nextval('exports_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY groups ALTER COLUMN id SET DEFAULT nextval('groups_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY histories ALTER COLUMN id SET DEFAULT nextval('histories_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY "incidentForms" ALTER COLUMN id SET DEFAULT nextval('"incidentForms_id_seq"'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY incidents ALTER COLUMN id SET DEFAULT nextval('incidents_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY locations ALTER COLUMN id SET DEFAULT nextval('locations_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY users ALTER COLUMN id SET DEFAULT nextval('users_id_seq'::regclass);
--
-- Name: SequelizeMeta_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY "SequelizeMetaBackup"
ADD CONSTRAINT "SequelizeMeta_pkey" PRIMARY KEY (id);
--
-- Name: SequelizeMeta_pkey1; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY "SequelizeMeta"
ADD CONSTRAINT "SequelizeMeta_pkey1" PRIMARY KEY (name);
--
-- Name: access_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY access_tokens
ADD CONSTRAINT access_tokens_pkey PRIMARY KEY (id);
--
-- TOC entry 2830 (class 2606 OID 16470)
-- Name: batteries_date_userId_key; Type: CONSTRAINT; Schema: public; Owner: test; Tablespace:
--
ALTER TABLE ONLY batteries
ADD CONSTRAINT "batteries_date_userId_key" UNIQUE (date, "userId");
--
-- Name: batteries_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY batteries
ADD CONSTRAINT batteries_pkey PRIMARY KEY (id);
--
-- Name: exports_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY exports
ADD CONSTRAINT exports_pkey PRIMARY KEY (id);
--
-- Name: groups_name_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY groups
ADD CONSTRAINT groups_name_key UNIQUE (name);
--
-- Name: groups_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY groups
ADD CONSTRAINT groups_pkey PRIMARY KEY (id);
--
-- Name: histories_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY histories
ADD CONSTRAINT histories_pkey PRIMARY KEY (id);
--
-- Name: incidentForms_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY "incidentForms"
ADD CONSTRAINT "incidentForms_pkey" PRIMARY KEY (id);
--
-- Name: incidents_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY incidents
ADD CONSTRAINT incidents_pkey PRIMARY KEY (id);
--
-- Name: locations_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY locations
ADD CONSTRAINT locations_pkey PRIMARY KEY (id);
--
-- Name: registrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY registrations
ADD CONSTRAINT registrations_pkey PRIMARY KEY (imei);
--
-- Name: users_email_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY users
ADD CONSTRAINT users_email_key UNIQUE (email);
--
-- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY users
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
--
-- Name: users_username_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY users
ADD CONSTRAINT users_username_key UNIQUE (username);
--
-- Name: videos_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY videos
ADD CONSTRAINT videos_pkey PRIMARY KEY (id);
--
-- TOC entry 2839 (class 2606 OID 16471)
-- Name: batteries_userId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: test
--
ALTER TABLE ONLY batteries
ADD CONSTRAINT "batteries_userId_fkey" FOREIGN KEY ("userId") REFERENCES users(id) ON UPDATE CASCADE;
--
-- TOC entry 2840 (class 2606 OID 16487)
-- Name: exports_exporterId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: test
--
ALTER TABLE ONLY exports
ADD CONSTRAINT "exports_exporterId_fkey" FOREIGN KEY ("exporterId") REFERENCES users(id) ON UPDATE CASCADE;
--
-- TOC entry 2841 (class 2606 OID 16492)
-- Name: exports_recorderId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: test
--
ALTER TABLE ONLY exports
ADD CONSTRAINT "exports_recorderId_fkey" FOREIGN KEY ("recorderId") REFERENCES users(id) ON UPDATE CASCADE;
--
-- TOC entry 2843 (class 2606 OID 16521)
-- Name: incidentForms_userId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: test
--
ALTER TABLE ONLY "incidentForms"
ADD CONSTRAINT "incidentForms_userId_fkey" FOREIGN KEY ("userId") REFERENCES users(id) ON UPDATE CASCADE;
--
-- Name: registration_trigger; Type: TRIGGER; Schema: public; Owner: -
--
CREATE TRIGGER registration_trigger AFTER INSERT OR UPDATE ON registrations FOR EACH ROW EXECUTE PROCEDURE archive_registration();
--
-- Name: incidents_userId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY incidents
ADD CONSTRAINT "incidents_userId_fkey" FOREIGN KEY ("userId") REFERENCES users(id) ON UPDATE CASCADE;
--
-- PostgreSQL database dump complete
--