-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitoring_draft_laws.sql
More file actions
350 lines (232 loc) · 9.78 KB
/
monitoring_draft_laws.sql
File metadata and controls
350 lines (232 loc) · 9.78 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
--
-- PostgreSQL database dump
--
\restrict XRhTb2PgPl45uqrzn1yG1l8HMriVJamGriEhG9m7JfIeD6e8CKPFcgMZCPQTceR
-- Dumped from database version 16.9
-- Dumped by pg_dump version 16.11 (Ubuntu 16.11-1.pgdg24.04+1)
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;
--
-- Name: megaplan; Type: DATABASE; Schema: -; Owner: -
--
CREATE DATABASE megaplan WITH TEMPLATE = template0 ENCODING = 'UTF8' LOCALE_PROVIDER = libc LC_COLLATE = 'C' LC_CTYPE = 'C.UTF-8';
\unrestrict XRhTb2PgPl45uqrzn1yG1l8HMriVJamGriEhG9m7JfIeD6e8CKPFcgMZCPQTceR
\connect megaplan
\restrict XRhTb2PgPl45uqrzn1yG1l8HMriVJamGriEhG9m7JfIeD6e8CKPFcgMZCPQTceR
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;
--
-- Name: monitoring_draft_laws; Type: SCHEMA; Schema: -; Owner: -
--
CREATE SCHEMA monitoring_draft_laws;
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: additional_files; Type: TABLE; Schema: monitoring_draft_laws; Owner: -
--
CREATE TABLE monitoring_draft_laws.additional_files (
id uuid DEFAULT gen_random_uuid() NOT NULL,
document_id text NOT NULL,
meta_info jsonb DEFAULT '{}'::jsonb NOT NULL,
object_id oid,
created timestamp with time zone DEFAULT now() NOT NULL
);
--
-- Name: cancellation_policy; Type: TABLE; Schema: monitoring_draft_laws; Owner: -
--
CREATE TABLE monitoring_draft_laws.cancellation_policy (
host text NOT NULL,
cancellation_phrases text[] DEFAULT '{}'::text[] NOT NULL
);
--
-- Name: documents_data; Type: TABLE; Schema: monitoring_draft_laws; Owner: -
--
CREATE TABLE monitoring_draft_laws.documents_data (
projectid text NOT NULL,
document_values jsonb NOT NULL,
created timestamp with time zone DEFAULT now() NOT NULL,
host text NOT NULL,
updated timestamp with time zone DEFAULT now() NOT NULL,
journal jsonb DEFAULT '[]'::jsonb NOT NULL,
archive boolean DEFAULT false NOT NULL
);
--
-- Name: COLUMN documents_data.updated; Type: COMMENT; Schema: monitoring_draft_laws; Owner: -
--
COMMENT ON COLUMN monitoring_draft_laws.documents_data.updated IS 'автообноление';
--
-- Name: favorites; Type: TABLE; Schema: monitoring_draft_laws; Owner: -
--
CREATE TABLE monitoring_draft_laws.favorites (
user_id integer NOT NULL,
project_id text NOT NULL
);
--
-- Name: logs; Type: TABLE; Schema: monitoring_draft_laws; Owner: -
--
CREATE TABLE monitoring_draft_laws.logs (
created timestamp with time zone DEFAULT now() NOT NULL,
doc_id text NOT NULL,
user_id integer NOT NULL,
"values" jsonb DEFAULT '{}'::jsonb NOT NULL
);
--
-- Name: roles_settings; Type: TABLE; Schema: monitoring_draft_laws; Owner: -
--
CREATE TABLE monitoring_draft_laws.roles_settings (
user_id integer NOT NULL,
is_admin boolean DEFAULT false NOT NULL,
is_responsible boolean DEFAULT false NOT NULL
);
--
-- Name: status_is_law; Type: VIEW; Schema: monitoring_draft_laws; Owner: -
--
CREATE VIEW monitoring_draft_laws.status_is_law AS
SELECT projectid,
true AS is_law
FROM ( SELECT dd.projectid,
jsonb_array_elements((dd.document_values -> 'journal'::text)) AS j
FROM monitoring_draft_laws.documents_data dd
WHERE (dd.host = 'sozd.duma.gov.ru'::text)) jj
WHERE (((j ->> 'header'::text) = '5.3 Рассмотрение законопроекта Государственной Думой'::text) AND ((j ->> 'decision'::text) ~~* '%принять закон%'::text));
--
-- Name: tg_chats; Type: TABLE; Schema: monitoring_draft_laws; Owner: -
--
CREATE TABLE monitoring_draft_laws.tg_chats (
chat_id bigint NOT NULL,
enabled boolean NOT NULL,
user_id integer DEFAULT 0 NOT NULL,
notification_type smallint DEFAULT 0 NOT NULL
);
--
-- Name: COLUMN tg_chats.chat_id; Type: COMMENT; Schema: monitoring_draft_laws; Owner: -
--
COMMENT ON COLUMN monitoring_draft_laws.tg_chats.chat_id IS 'ID чата в телеграмм';
--
-- Name: COLUMN tg_chats.user_id; Type: COMMENT; Schema: monitoring_draft_laws; Owner: -
--
COMMENT ON COLUMN monitoring_draft_laws.tg_chats.user_id IS 'ID зера в мегаплане';
--
-- Name: COLUMN tg_chats.notification_type; Type: COMMENT; Schema: monitoring_draft_laws; Owner: -
--
COMMENT ON COLUMN monitoring_draft_laws.tg_chats.notification_type IS 'тип уведомления, фильтр';
--
-- Name: additional_files additional_files_pk; Type: CONSTRAINT; Schema: monitoring_draft_laws; Owner: -
--
ALTER TABLE ONLY monitoring_draft_laws.additional_files
ADD CONSTRAINT additional_files_pk PRIMARY KEY (id);
--
-- Name: additional_files additional_files_unique; Type: CONSTRAINT; Schema: monitoring_draft_laws; Owner: -
--
ALTER TABLE ONLY monitoring_draft_laws.additional_files
ADD CONSTRAINT additional_files_unique UNIQUE (object_id);
--
-- Name: cancellation_policy cancellation_policy_un; Type: CONSTRAINT; Schema: monitoring_draft_laws; Owner: -
--
ALTER TABLE ONLY monitoring_draft_laws.cancellation_policy
ADD CONSTRAINT cancellation_policy_un UNIQUE (host);
--
-- Name: documents_data documents_data_pk; Type: CONSTRAINT; Schema: monitoring_draft_laws; Owner: -
--
ALTER TABLE ONLY monitoring_draft_laws.documents_data
ADD CONSTRAINT documents_data_pk PRIMARY KEY (projectid);
--
-- Name: favorites favorites_un; Type: CONSTRAINT; Schema: monitoring_draft_laws; Owner: -
--
ALTER TABLE ONLY monitoring_draft_laws.favorites
ADD CONSTRAINT favorites_un UNIQUE (user_id, project_id);
--
-- Name: roles_settings roles_settings_un; Type: CONSTRAINT; Schema: monitoring_draft_laws; Owner: -
--
ALTER TABLE ONLY monitoring_draft_laws.roles_settings
ADD CONSTRAINT roles_settings_un UNIQUE (user_id);
--
-- Name: tg_chats tg_chats_pk; Type: CONSTRAINT; Schema: monitoring_draft_laws; Owner: -
--
ALTER TABLE ONLY monitoring_draft_laws.tg_chats
ADD CONSTRAINT tg_chats_pk PRIMARY KEY (chat_id);
--
-- Name: additional_files_id_idx; Type: INDEX; Schema: monitoring_draft_laws; Owner: -
--
CREATE UNIQUE INDEX additional_files_id_idx ON monitoring_draft_laws.additional_files USING btree (id);
--
-- Name: cancellation_phrases_idx; Type: INDEX; Schema: monitoring_draft_laws; Owner: -
--
CREATE INDEX cancellation_phrases_idx ON monitoring_draft_laws.cancellation_policy USING gin (cancellation_phrases);
--
-- Name: document_valuess_idx; Type: INDEX; Schema: monitoring_draft_laws; Owner: -
--
CREATE INDEX document_valuess_idx ON monitoring_draft_laws.documents_data USING gin (document_values);
--
-- Name: documents_data_host_idx; Type: INDEX; Schema: monitoring_draft_laws; Owner: -
--
CREATE INDEX documents_data_host_idx ON monitoring_draft_laws.documents_data USING btree (host);
--
-- Name: logs_created_idx; Type: INDEX; Schema: monitoring_draft_laws; Owner: -
--
CREATE INDEX logs_created_idx ON monitoring_draft_laws.logs USING btree (created);
--
-- Name: logs_doc_id_idx; Type: INDEX; Schema: monitoring_draft_laws; Owner: -
--
CREATE INDEX logs_doc_id_idx ON monitoring_draft_laws.logs USING btree (doc_id);
--
-- Name: logs_user_id_idx; Type: INDEX; Schema: monitoring_draft_laws; Owner: -
--
CREATE INDEX logs_user_id_idx ON monitoring_draft_laws.logs USING btree (user_id);
--
-- Name: tg_chats_enabled_idx; Type: INDEX; Schema: monitoring_draft_laws; Owner: -
--
CREATE INDEX tg_chats_enabled_idx ON monitoring_draft_laws.tg_chats USING btree (enabled);
--
-- Name: tg_chats_notification_type_idx; Type: INDEX; Schema: monitoring_draft_laws; Owner: -
--
CREATE INDEX tg_chats_notification_type_idx ON monitoring_draft_laws.tg_chats USING btree (notification_type);
--
-- Name: tg_chats_user_id_idx; Type: INDEX; Schema: monitoring_draft_laws; Owner: -
--
CREATE INDEX tg_chats_user_id_idx ON monitoring_draft_laws.tg_chats USING btree (user_id);
--
-- Name: additional_files additional_files_documents_data_fk; Type: FK CONSTRAINT; Schema: monitoring_draft_laws; Owner: -
--
ALTER TABLE ONLY monitoring_draft_laws.additional_files
ADD CONSTRAINT additional_files_documents_data_fk FOREIGN KEY (document_id) REFERENCES monitoring_draft_laws.documents_data(projectid) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: favorites favorites_fk; Type: FK CONSTRAINT; Schema: monitoring_draft_laws; Owner: -
--
ALTER TABLE ONLY monitoring_draft_laws.favorites
ADD CONSTRAINT favorites_fk FOREIGN KEY (project_id) REFERENCES monitoring_draft_laws.documents_data(projectid) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: logs logs_fk; Type: FK CONSTRAINT; Schema: monitoring_draft_laws; Owner: -
--
ALTER TABLE ONLY monitoring_draft_laws.logs
ADD CONSTRAINT logs_fk FOREIGN KEY (doc_id) REFERENCES monitoring_draft_laws.documents_data(projectid) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: roles_settings roles_settings_fk; Type: FK CONSTRAINT; Schema: monitoring_draft_laws; Owner: -
--
ALTER TABLE ONLY monitoring_draft_laws.roles_settings
ADD CONSTRAINT roles_settings_fk FOREIGN KEY (user_id) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: tg_chats tg_chats_users_fk; Type: FK CONSTRAINT; Schema: monitoring_draft_laws; Owner: -
--
ALTER TABLE ONLY monitoring_draft_laws.tg_chats
ADD CONSTRAINT tg_chats_users_fk FOREIGN KEY (user_id) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- PostgreSQL database dump complete
--
\unrestrict XRhTb2PgPl45uqrzn1yG1l8HMriVJamGriEhG9m7JfIeD6e8CKPFcgMZCPQTceR