-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_dump_smod.sql
More file actions
519 lines (356 loc) · 12.1 KB
/
Copy pathdb_dump_smod.sql
File metadata and controls
519 lines (356 loc) · 12.1 KB
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
--
-- PostgreSQL database dump
--
-- Dumped from database version 9.4.8
-- Dumped by pg_dump version 9.4.8
-- Started on 2017-01-17 18:17:46
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;
--
-- TOC entry 1 (class 3079 OID 11855)
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--
-- TOC entry 2137 (class 0 OID 0)
-- Dependencies: 1
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
--
-- TOC entry 2 (class 3079 OID 1092259)
-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;
--
-- TOC entry 2138 (class 0 OID 0)
-- Dependencies: 2
-- Name: EXTENSION pgcrypto; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions';
--
-- TOC entry 3 (class 3079 OID 1092248)
-- Name: uuid-ossp; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public;
--
-- TOC entry 2139 (class 0 OID 0)
-- Dependencies: 3
-- Name: EXTENSION "uuid-ossp"; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UUIDs)';
SET search_path = public, pg_catalog;
SET default_with_oids = false;
--
-- TOC entry 178 (class 1259 OID 1092307)
-- Name: attachment; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE attachment (
id uuid DEFAULT gen_random_uuid() NOT NULL,
type text NOT NULL,
path text,
filename text,
size integer
);
--
-- TOC entry 184 (class 1259 OID 1100460)
-- Name: conversation; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE conversation (
id uuid DEFAULT gen_random_uuid() NOT NULL,
begin_at timestamp without time zone DEFAULT now(),
last_message_id uuid,
message_group_id uuid
);
--
-- TOC entry 183 (class 1259 OID 1092381)
-- Name: device; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE device (
id uuid DEFAULT gen_random_uuid() NOT NULL,
handle text
);
--
-- TOC entry 182 (class 1259 OID 1092367)
-- Name: member; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE member (
id uuid DEFAULT gen_random_uuid() NOT NULL,
phone text
);
--
-- TOC entry 2140 (class 0 OID 0)
-- Dependencies: 182
-- Name: COLUMN member.phone; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON COLUMN member.phone IS 'Here we can reffer to
table member where actual phone will be placed';
--
-- TOC entry 185 (class 1259 OID 1100503)
-- Name: member_device; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE member_device (
id uuid DEFAULT gen_random_uuid() NOT NULL,
device_id uuid,
member_id uuid
);
--
-- TOC entry 177 (class 1259 OID 1092297)
-- Name: message; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE message (
id uuid DEFAULT gen_random_uuid() NOT NULL,
"timestamp" timestamp without time zone DEFAULT now() NOT NULL,
sender_id uuid,
text text NOT NULL,
receiver_id uuid,
service_id integer,
group_id uuid NOT NULL,
device_id uuid NOT NULL,
conversation_id uuid NOT NULL,
is_attachment smallint DEFAULT 0 NOT NULL
);
--
-- TOC entry 2141 (class 0 OID 0)
-- Dependencies: 177
-- Name: COLUMN message.sender_id; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON COLUMN message.sender_id IS 'from_me';
--
-- TOC entry 2142 (class 0 OID 0)
-- Dependencies: 177
-- Name: COLUMN message.receiver_id; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON COLUMN message.receiver_id IS 'handle';
--
-- TOC entry 181 (class 1259 OID 1092334)
-- Name: message_attachment; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE message_attachment (
attachment_id uuid,
message_id uuid NOT NULL,
id uuid DEFAULT gen_random_uuid() NOT NULL
);
--
-- TOC entry 179 (class 1259 OID 1092316)
-- Name: message_group; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE message_group (
id uuid DEFAULT gen_random_uuid() NOT NULL,
name text
);
--
-- TOC entry 180 (class 1259 OID 1092325)
-- Name: message_group_member; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE message_group_member (
id uuid DEFAULT gen_random_uuid() NOT NULL,
group_id uuid,
member_id uuid
);
--
-- TOC entry 176 (class 1259 OID 1092238)
-- Name: message_service; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE message_service (
id integer NOT NULL,
name text NOT NULL
);
--
-- TOC entry 175 (class 1259 OID 1092236)
-- Name: message_service_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE message_service_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- TOC entry 2143 (class 0 OID 0)
-- Dependencies: 175
-- Name: message_service_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE message_service_id_seq OWNED BY message_service.id;
--
-- TOC entry 1969 (class 2604 OID 1092241)
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY message_service ALTER COLUMN id SET DEFAULT nextval('message_service_id_seq'::regclass);
--
-- TOC entry 1991 (class 2606 OID 1092314)
-- Name: attachment_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY attachment
ADD CONSTRAINT attachment_pkey PRIMARY KEY (id);
--
-- TOC entry 2010 (class 2606 OID 1100465)
-- Name: conversation_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY conversation
ADD CONSTRAINT conversation_pkey PRIMARY KEY (id);
--
-- TOC entry 2007 (class 2606 OID 1092388)
-- Name: device_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY device
ADD CONSTRAINT device_pkey PRIMARY KEY (id);
--
-- TOC entry 2012 (class 2606 OID 1100507)
-- Name: member_device_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY member_device
ADD CONSTRAINT member_device_pkey PRIMARY KEY (id);
--
-- TOC entry 2001 (class 2606 OID 1101046)
-- Name: message_attachment_id_pk; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY message_attachment
ADD CONSTRAINT message_attachment_id_pk PRIMARY KEY (id);
--
-- TOC entry 1999 (class 2606 OID 1092329)
-- Name: message_group_member_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY message_group_member
ADD CONSTRAINT message_group_member_pkey PRIMARY KEY (id);
--
-- TOC entry 1994 (class 2606 OID 1092323)
-- Name: message_group_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY message_group
ADD CONSTRAINT message_group_pkey PRIMARY KEY (id);
--
-- TOC entry 2004 (class 2606 OID 1092374)
-- Name: message_member_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY member
ADD CONSTRAINT message_member_pkey PRIMARY KEY (id);
--
-- TOC entry 1988 (class 2606 OID 1092305)
-- Name: message_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY message
ADD CONSTRAINT message_pkey PRIMARY KEY (id);
--
-- TOC entry 1984 (class 2606 OID 1092246)
-- Name: message_service_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY message_service
ADD CONSTRAINT message_service_pkey PRIMARY KEY (id);
--
-- TOC entry 1989 (class 1259 OID 1092315)
-- Name: attachment_id_uindex; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX attachment_id_uindex ON attachment USING btree (id);
--
-- TOC entry 2008 (class 1259 OID 1100466)
-- Name: conversation_begin_at_index; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX conversation_begin_at_index ON conversation USING btree (begin_at);
--
-- TOC entry 2005 (class 1259 OID 1092389)
-- Name: device_handle_uindex; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX device_handle_uindex ON device USING btree (handle);
--
-- TOC entry 1985 (class 1259 OID 1100467)
-- Name: message_conversation_id_index; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX message_conversation_id_index ON message USING btree (conversation_id);
--
-- TOC entry 1992 (class 1259 OID 1092324)
-- Name: message_group_id_uindex; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX message_group_id_uindex ON message_group USING btree (id);
--
-- TOC entry 1995 (class 1259 OID 1092361)
-- Name: message_group_member_group_id_index; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX message_group_member_group_id_index ON message_group_member USING btree (group_id);
--
-- TOC entry 1996 (class 1259 OID 1092330)
-- Name: message_group_member_id_uindex; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX message_group_member_id_uindex ON message_group_member USING btree (id);
--
-- TOC entry 1997 (class 1259 OID 1092331)
-- Name: message_group_member_member_id_group_id_index; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX message_group_member_member_id_group_id_index ON message_group_member USING btree (member_id, group_id);
--
-- TOC entry 1986 (class 1259 OID 1092306)
-- Name: message_id_uindex; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX message_id_uindex ON message USING btree (id);
--
-- TOC entry 2002 (class 1259 OID 1092375)
-- Name: message_member_phone_uindex; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX message_member_phone_uindex ON member USING btree (phone);
--
-- TOC entry 1982 (class 1259 OID 1092247)
-- Name: message_service_name_uindex; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX message_service_name_uindex ON message_service USING btree (name);
--
-- TOC entry 2019 (class 2606 OID 1100907)
-- Name: conversation_message_group_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY conversation
ADD CONSTRAINT conversation_message_group_id_fk FOREIGN KEY (message_group_id) REFERENCES message_group(id);
--
-- TOC entry 2021 (class 2606 OID 1100513)
-- Name: member_device_device_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY member_device
ADD CONSTRAINT member_device_device_id_fk FOREIGN KEY (device_id) REFERENCES device(id);
--
-- TOC entry 2020 (class 2606 OID 1100508)
-- Name: member_device_member_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY member_device
ADD CONSTRAINT member_device_member_id_fk FOREIGN KEY (member_id) REFERENCES member(id);
--
-- TOC entry 2017 (class 2606 OID 1092340)
-- Name: message_attachment_attachment_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY message_attachment
ADD CONSTRAINT message_attachment_attachment_id_fk FOREIGN KEY (attachment_id) REFERENCES attachment(id) ON DELETE CASCADE;
--
-- TOC entry 2018 (class 2606 OID 1092345)
-- Name: message_attachment_message_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY message_attachment
ADD CONSTRAINT message_attachment_message_id_fk FOREIGN KEY (message_id) REFERENCES message(id) ON DELETE CASCADE;
--
-- TOC entry 2014 (class 2606 OID 1100473)
-- Name: message_conversation_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY message
ADD CONSTRAINT message_conversation_id_fk FOREIGN KEY (conversation_id) REFERENCES conversation(id);
--
-- TOC entry 2015 (class 2606 OID 1092376)
-- Name: message_group_member_member_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY message_group_member
ADD CONSTRAINT message_group_member_member_id_fk FOREIGN KEY (member_id) REFERENCES member(id);
--
-- TOC entry 2016 (class 2606 OID 1100478)
-- Name: message_group_member_message_group_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY message_group_member
ADD CONSTRAINT message_group_member_message_group_id_fk FOREIGN KEY (group_id) REFERENCES message_group(id);
--
-- TOC entry 2013 (class 2606 OID 1092362)
-- Name: message_message_service_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY message
ADD CONSTRAINT message_message_service_id_fk FOREIGN KEY (service_id) REFERENCES message_service(id);
-- Completed on 2017-01-17 18:17:46
--
-- PostgreSQL database dump complete
--