-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.sql
583 lines (413 loc) · 13.4 KB
/
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
--
-- PostgreSQL database cluster dump
--
-- Started on 2024-01-17 16:27:38 UTC
SET default_transaction_read_only = off;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
--
-- Roles
--
CREATE ROLE docker;
ALTER ROLE docker WITH SUPERUSER INHERIT CREATEROLE CREATEDB LOGIN REPLICATION BYPASSRLS PASSWORD 'SCRAM-SHA-256$4096:6CZz3kDfU9wL4QNPDewNSw==$bOc02dFEi/7fcHwoGRIB9qxKz0b7QWjQoqMheU9lx+Y=:/UyWa8vZP7Z0pqIt1M3jXtymDeG+PxOJbDokQQp28H0=';
--
-- User Configurations
--
--
-- Databases
--
--
-- Database "template1" dump
--
\connect template1
--
-- PostgreSQL database dump
--
-- Dumped from database version 16.1 (Debian 16.1-1.pgdg120+1)
-- Dumped by pg_dump version 16.1
-- Started on 2024-01-17 16:27:38 UTC
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 xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
-- Completed on 2024-01-17 16:27:38 UTC
--
-- PostgreSQL database dump complete
--
--
-- Database "db" dump
--
--
-- PostgreSQL database dump
--
-- Dumped from database version 16.1 (Debian 16.1-1.pgdg120+1)
-- Dumped by pg_dump version 16.1
-- Started on 2024-01-17 16:27:38 UTC
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 xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- TOC entry 3407 (class 1262 OID 16384)
-- Name: db; Type: DATABASE; Schema: -; Owner: docker
--
CREATE DATABASE db WITH TEMPLATE = template0 ENCODING = 'UTF8' LOCALE_PROVIDER = libc LOCALE = 'en_US.utf8';
ALTER DATABASE db OWNER TO docker;
\connect db
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 xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- TOC entry 229 (class 1255 OID 16497)
-- Name: get_user_notes(integer); Type: FUNCTION; Schema: public; Owner: docker
--
CREATE FUNCTION public.get_user_notes(userid integer) RETURNS TABLE(user_id bigint, login text, note_id integer, note_content text)
LANGUAGE plpgsql
AS $$
BEGIN
RETURN QUERY SELECT unv.user_id, unv.login, unv.note_id, unv.note_content
FROM user_notes_view unv
WHERE unv.user_id = userid;
END;
$$;
ALTER FUNCTION public.get_user_notes(userid integer) OWNER TO docker;
--
-- TOC entry 225 (class 1255 OID 16399)
-- Name: set_add_date_time(); Type: FUNCTION; Schema: public; Owner: docker
--
CREATE FUNCTION public.set_add_date_time() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
-- Set add_date to the current date and time
NEW.add_date := CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.set_add_date_time() OWNER TO docker;
--
-- TOC entry 226 (class 1255 OID 16485)
-- Name: set_default_role(); Type: FUNCTION; Schema: public; Owner: docker
--
CREATE FUNCTION public.set_default_role() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NEW.role_id := 2;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.set_default_role() OWNER TO docker;
--
-- TOC entry 227 (class 1255 OID 16481)
-- Name: set_note_creation_date(); Type: FUNCTION; Schema: public; Owner: docker
--
CREATE FUNCTION public.set_note_creation_date() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NEW.creation_date := CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.set_note_creation_date() OWNER TO docker;
--
-- TOC entry 228 (class 1255 OID 16483)
-- Name: update_last_modified(); Type: FUNCTION; Schema: public; Owner: docker
--
CREATE FUNCTION public.update_last_modified() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NEW.last_modified := CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.update_last_modified() OWNER TO docker;
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- TOC entry 220 (class 1259 OID 16439)
-- Name: note_roles; Type: TABLE; Schema: public; Owner: docker
--
CREATE TABLE public.note_roles (
note_role_id integer NOT NULL,
note_role_name character varying(50) NOT NULL
);
ALTER TABLE public.note_roles OWNER TO docker;
--
-- TOC entry 219 (class 1259 OID 16438)
-- Name: note_roles_note_role_id_seq; Type: SEQUENCE; Schema: public; Owner: docker
--
CREATE SEQUENCE public.note_roles_note_role_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.note_roles_note_role_id_seq OWNER TO docker;
--
-- TOC entry 3408 (class 0 OID 0)
-- Dependencies: 219
-- Name: note_roles_note_role_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: docker
--
ALTER SEQUENCE public.note_roles_note_role_id_seq OWNED BY public.note_roles.note_role_id;
--
-- TOC entry 218 (class 1259 OID 16408)
-- Name: notes; Type: TABLE; Schema: public; Owner: docker
--
CREATE TABLE public.notes (
note_id integer NOT NULL,
note_title character varying(100) NOT NULL,
note_content text NOT NULL,
creation_date timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
last_modified timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE public.notes OWNER TO docker;
--
-- TOC entry 217 (class 1259 OID 16407)
-- Name: notes_note_id_seq; Type: SEQUENCE; Schema: public; Owner: docker
--
CREATE SEQUENCE public.notes_note_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.notes_note_id_seq OWNER TO docker;
--
-- TOC entry 3409 (class 0 OID 0)
-- Dependencies: 217
-- Name: notes_note_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: docker
--
ALTER SEQUENCE public.notes_note_id_seq OWNED BY public.notes.note_id;
--
-- TOC entry 222 (class 1259 OID 16448)
-- Name: roles; Type: TABLE; Schema: public; Owner: docker
--
CREATE TABLE public.roles (
role_id integer NOT NULL,
role_name character varying(50) NOT NULL
);
ALTER TABLE public.roles OWNER TO docker;
--
-- TOC entry 221 (class 1259 OID 16447)
-- Name: roles_role_id_seq; Type: SEQUENCE; Schema: public; Owner: docker
--
CREATE SEQUENCE public.roles_role_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.roles_role_id_seq OWNER TO docker;
--
-- TOC entry 3410 (class 0 OID 0)
-- Dependencies: 221
-- Name: roles_role_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: docker
--
ALTER SEQUENCE public.roles_role_id_seq OWNED BY public.roles.role_id;
--
-- TOC entry 223 (class 1259 OID 16461)
-- Name: user_notes; Type: TABLE; Schema: public; Owner: docker
--
CREATE TABLE public.user_notes (
user_id integer NOT NULL,
note_id integer NOT NULL,
note_role_id integer
);
ALTER TABLE public.user_notes OWNER TO docker;
--
-- TOC entry 216 (class 1259 OID 16390)
-- Name: users; Type: TABLE; Schema: public; Owner: docker
--
CREATE TABLE public.users (
user_id bigint NOT NULL,
login text NOT NULL,
email text NOT NULL,
password text NOT NULL,
add_date timestamp with time zone,
role_id bigint
);
ALTER TABLE public.users OWNER TO docker;
--
-- TOC entry 224 (class 1259 OID 16487)
-- Name: user_notes_view; Type: VIEW; Schema: public; Owner: docker
--
CREATE VIEW public.user_notes_view AS
SELECT u.user_id,
u.login,
n.note_id,
n.note_content
FROM ((public.users u
JOIN public.user_notes un ON ((u.user_id = un.user_id)))
JOIN public.notes n ON ((un.note_id = n.note_id)))
ORDER BY u.user_id;
ALTER VIEW public.user_notes_view OWNER TO docker;
--
-- TOC entry 215 (class 1259 OID 16389)
-- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: docker
--
ALTER TABLE public.users ALTER COLUMN user_id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.users_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
--
-- TOC entry 3234 (class 2604 OID 16442)
-- Name: note_roles note_role_id; Type: DEFAULT; Schema: public; Owner: docker
--
ALTER TABLE ONLY public.note_roles ALTER COLUMN note_role_id SET DEFAULT nextval('public.note_roles_note_role_id_seq'::regclass);
--
-- TOC entry 3231 (class 2604 OID 16411)
-- Name: notes note_id; Type: DEFAULT; Schema: public; Owner: docker
--
ALTER TABLE ONLY public.notes ALTER COLUMN note_id SET DEFAULT nextval('public.notes_note_id_seq'::regclass);
--
-- TOC entry 3235 (class 2604 OID 16451)
-- Name: roles role_id; Type: DEFAULT; Schema: public; Owner: docker
--
ALTER TABLE ONLY public.roles ALTER COLUMN role_id SET DEFAULT nextval('public.roles_role_id_seq'::regclass);
--
-- TOC entry 3241 (class 2606 OID 16446)
-- Name: note_roles note_roles_note_role_name_key; Type: CONSTRAINT; Schema: public; Owner: docker
--
ALTER TABLE ONLY public.note_roles
ADD CONSTRAINT note_roles_note_role_name_key UNIQUE (note_role_name);
--
-- TOC entry 3243 (class 2606 OID 16444)
-- Name: note_roles note_roles_pkey; Type: CONSTRAINT; Schema: public; Owner: docker
--
ALTER TABLE ONLY public.note_roles
ADD CONSTRAINT note_roles_pkey PRIMARY KEY (note_role_id);
--
-- TOC entry 3239 (class 2606 OID 16417)
-- Name: notes notes_pkey; Type: CONSTRAINT; Schema: public; Owner: docker
--
ALTER TABLE ONLY public.notes
ADD CONSTRAINT notes_pkey PRIMARY KEY (note_id);
--
-- TOC entry 3245 (class 2606 OID 16453)
-- Name: roles roles_pkey; Type: CONSTRAINT; Schema: public; Owner: docker
--
ALTER TABLE ONLY public.roles
ADD CONSTRAINT roles_pkey PRIMARY KEY (role_id);
--
-- TOC entry 3247 (class 2606 OID 16455)
-- Name: roles roles_role_name_key; Type: CONSTRAINT; Schema: public; Owner: docker
--
ALTER TABLE ONLY public.roles
ADD CONSTRAINT roles_role_name_key UNIQUE (role_name);
--
-- TOC entry 3249 (class 2606 OID 16465)
-- Name: user_notes user_notes_pkey; Type: CONSTRAINT; Schema: public; Owner: docker
--
ALTER TABLE ONLY public.user_notes
ADD CONSTRAINT user_notes_pkey PRIMARY KEY (user_id, note_id);
--
-- TOC entry 3237 (class 2606 OID 16396)
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: docker
--
ALTER TABLE ONLY public.users
ADD CONSTRAINT users_pkey PRIMARY KEY (user_id);
--
-- TOC entry 3254 (class 2620 OID 16400)
-- Name: users add_date_time_trigger; Type: TRIGGER; Schema: public; Owner: docker
--
CREATE TRIGGER add_date_time_trigger BEFORE INSERT ON public.users FOR EACH ROW EXECUTE FUNCTION public.set_add_date_time();
--
-- TOC entry 3256 (class 2620 OID 16484)
-- Name: notes last_modified_trigger; Type: TRIGGER; Schema: public; Owner: docker
--
CREATE TRIGGER last_modified_trigger BEFORE UPDATE ON public.notes FOR EACH ROW EXECUTE FUNCTION public.update_last_modified();
--
-- TOC entry 3257 (class 2620 OID 16482)
-- Name: notes note_creation_date_trigger; Type: TRIGGER; Schema: public; Owner: docker
--
CREATE TRIGGER note_creation_date_trigger BEFORE INSERT ON public.notes FOR EACH ROW EXECUTE FUNCTION public.set_note_creation_date();
--
-- TOC entry 3255 (class 2620 OID 16486)
-- Name: users trigger_set_default_role; Type: TRIGGER; Schema: public; Owner: docker
--
CREATE TRIGGER trigger_set_default_role BEFORE INSERT ON public.users FOR EACH ROW EXECUTE FUNCTION public.set_default_role();
--
-- TOC entry 3251 (class 2606 OID 16471)
-- Name: user_notes user_notes_note_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: docker
--
ALTER TABLE ONLY public.user_notes
ADD CONSTRAINT user_notes_note_id_fkey FOREIGN KEY (note_id) REFERENCES public.notes(note_id);
--
-- TOC entry 3252 (class 2606 OID 16476)
-- Name: user_notes user_notes_note_role_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: docker
--
ALTER TABLE ONLY public.user_notes
ADD CONSTRAINT user_notes_note_role_id_fkey FOREIGN KEY (note_role_id) REFERENCES public.note_roles(note_role_id);
--
-- TOC entry 3253 (class 2606 OID 16466)
-- Name: user_notes user_notes_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: docker
--
ALTER TABLE ONLY public.user_notes
ADD CONSTRAINT user_notes_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(user_id);
--
-- TOC entry 3250 (class 2606 OID 16456)
-- Name: users users_role_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: docker
--
ALTER TABLE ONLY public.users
ADD CONSTRAINT users_role_id_fkey FOREIGN KEY (role_id) REFERENCES public.roles(role_id);
-- Completed on 2024-01-17 16:27:38 UTC
--
-- PostgreSQL database dump complete
--
--
-- Database "postgres" dump
--
\connect postgres
--
-- PostgreSQL database dump
--
-- Dumped from database version 16.1 (Debian 16.1-1.pgdg120+1)
-- Dumped by pg_dump version 16.1
-- Started on 2024-01-17 16:27:38 UTC
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 xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
-- Completed on 2024-01-17 16:27:38 UTC
--
-- PostgreSQL database dump complete
--
-- Completed on 2024-01-17 16:27:38 UTC
--
-- PostgreSQL database cluster dump complete
--