-
Notifications
You must be signed in to change notification settings - Fork 0
/
gutenberg_scores.sql
434 lines (279 loc) · 10.7 KB
/
gutenberg_scores.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
--
-- PostgreSQL database dump
--
-- Dumped from database version 10.15
-- Dumped by pg_dump version 10.15
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: scores; Type: SCHEMA; Schema: -; Owner: gutenberg
--
CREATE SCHEMA scores;
ALTER SCHEMA scores OWNER TO gutenberg;
SET default_tablespace = '';
SET default_with_oids = true;
--
-- Name: also_downloads; Type: TABLE; Schema: scores; Owner: gutenberg
--
CREATE TABLE scores.also_downloads (
id integer,
fk_books integer NOT NULL,
date date
);
ALTER TABLE scores.also_downloads OWNER TO gutenberg;
--
-- Name: also_downloads_id_seq; Type: SEQUENCE; Schema: scores; Owner: gutenberg
--
CREATE SEQUENCE scores.also_downloads_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE scores.also_downloads_id_seq OWNER TO gutenberg;
SET default_with_oids = false;
--
-- Name: author_downloads; Type: TABLE; Schema: scores; Owner: gutenberg
--
CREATE TABLE scores.author_downloads (
date date NOT NULL,
fk_authors integer NOT NULL,
downloads integer NOT NULL
);
ALTER TABLE scores.author_downloads OWNER TO gutenberg;
SET default_with_oids = true;
--
-- Name: book_downloads; Type: TABLE; Schema: scores; Owner: gutenberg
--
CREATE TABLE scores.book_downloads (
pk integer DEFAULT nextval(('scores.book_downloads_pk_seq'::text)::regclass) NOT NULL,
date date NOT NULL,
fk_books integer NOT NULL,
downloads integer NOT NULL
);
ALTER TABLE scores.book_downloads OWNER TO gutenberg;
--
-- Name: book_downloads_pk_seq; Type: SEQUENCE; Schema: scores; Owner: gutenberg
--
CREATE SEQUENCE scores.book_downloads_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE scores.book_downloads_pk_seq OWNER TO gutenberg;
--
-- Name: book_downloads_pk_seq; Type: SEQUENCE OWNED BY; Schema: scores; Owner: gutenberg
--
ALTER SEQUENCE scores.book_downloads_pk_seq OWNED BY scores.book_downloads.pk;
SET default_with_oids = false;
--
-- Name: bookshelf_downloads; Type: TABLE; Schema: scores; Owner: gutenberg
--
CREATE TABLE scores.bookshelf_downloads (
date date NOT NULL,
fk_bookshelves integer NOT NULL,
downloads integer NOT NULL
);
ALTER TABLE scores.bookshelf_downloads OWNER TO gutenberg;
SET default_with_oids = true;
--
-- Name: file_downloads; Type: TABLE; Schema: scores; Owner: gutenberg
--
CREATE TABLE scores.file_downloads (
pk integer DEFAULT nextval(('scores.file_downloads_pk_seq'::text)::regclass) NOT NULL,
date date NOT NULL,
fk_files integer NOT NULL,
downloads integer
);
ALTER TABLE scores.file_downloads OWNER TO gutenberg;
--
-- Name: file_downloads_pk_seq; Type: SEQUENCE; Schema: scores; Owner: gutenberg
--
CREATE SEQUENCE scores.file_downloads_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE scores.file_downloads_pk_seq OWNER TO gutenberg;
--
-- Name: file_downloads_pk_seq; Type: SEQUENCE OWNED BY; Schema: scores; Owner: gutenberg
--
ALTER SEQUENCE scores.file_downloads_pk_seq OWNED BY scores.file_downloads.pk;
SET default_with_oids = false;
--
-- Name: filetype_downloads; Type: TABLE; Schema: scores; Owner: gutenberg
--
CREATE TABLE scores.filetype_downloads (
date date NOT NULL,
fk_filetypes character varying(20) NOT NULL,
downloads integer NOT NULL
);
ALTER TABLE scores.filetype_downloads OWNER TO gutenberg;
--
-- Name: subject_downloads; Type: TABLE; Schema: scores; Owner: gutenberg
--
CREATE TABLE scores.subject_downloads (
date date NOT NULL,
fk_subjects integer NOT NULL,
downloads integer NOT NULL
);
ALTER TABLE scores.subject_downloads OWNER TO gutenberg;
--
-- Name: v_by_filetype; Type: VIEW; Schema: scores; Owner: gutenberg
--
CREATE VIEW scores.v_by_filetype AS
SELECT filetype_downloads.fk_filetypes AS filetypes,
sum(filetype_downloads.downloads) AS downloads
FROM scores.filetype_downloads
GROUP BY filetype_downloads.fk_filetypes
ORDER BY (sum(filetype_downloads.downloads)) DESC;
ALTER TABLE scores.v_by_filetype OWNER TO gutenberg;
--
-- Name: book_downloads book_downloads_pkey; Type: CONSTRAINT; Schema: scores; Owner: gutenberg
--
ALTER TABLE ONLY scores.book_downloads
ADD CONSTRAINT book_downloads_pkey PRIMARY KEY (pk);
--
-- Name: bookshelf_downloads bookshelf_downloads_date_key; Type: CONSTRAINT; Schema: scores; Owner: gutenberg
--
ALTER TABLE ONLY scores.bookshelf_downloads
ADD CONSTRAINT bookshelf_downloads_date_key UNIQUE (date, fk_bookshelves);
--
-- Name: file_downloads file_downloads_pkey; Type: CONSTRAINT; Schema: scores; Owner: gutenberg
--
ALTER TABLE ONLY scores.file_downloads
ADD CONSTRAINT file_downloads_pkey PRIMARY KEY (pk);
--
-- Name: filetype_downloads filetype_downloads_pkey; Type: CONSTRAINT; Schema: scores; Owner: gutenberg
--
ALTER TABLE ONLY scores.filetype_downloads
ADD CONSTRAINT filetype_downloads_pkey PRIMARY KEY (date, fk_filetypes);
--
-- Name: author_downloads ix_author_downloads_date_fk_authors; Type: CONSTRAINT; Schema: scores; Owner: gutenberg
--
ALTER TABLE ONLY scores.author_downloads
ADD CONSTRAINT ix_author_downloads_date_fk_authors UNIQUE (date, fk_authors);
--
-- Name: ix_also_downloads_fk_books; Type: INDEX; Schema: scores; Owner: gutenberg
--
CREATE UNIQUE INDEX ix_also_downloads_fk_books ON scores.also_downloads USING btree (fk_books, id);
--
-- Name: ix_also_downloads_id; Type: INDEX; Schema: scores; Owner: gutenberg
--
CREATE INDEX ix_also_downloads_id ON scores.also_downloads USING btree (id);
--
-- Name: ix_book_downloads_date_fk_books; Type: INDEX; Schema: scores; Owner: gutenberg
--
CREATE UNIQUE INDEX ix_book_downloads_date_fk_books ON scores.book_downloads USING btree (date, fk_books);
--
-- Name: ix_file_downloads_date_fk_files; Type: INDEX; Schema: scores; Owner: gutenberg
--
CREATE UNIQUE INDEX ix_file_downloads_date_fk_files ON scores.file_downloads USING btree (date, fk_files);
--
-- Name: file_downloads $1; Type: FK CONSTRAINT; Schema: scores; Owner: gutenberg
--
ALTER TABLE ONLY scores.file_downloads
ADD CONSTRAINT "$1" FOREIGN KEY (fk_files) REFERENCES public.files(pk) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: book_downloads $1; Type: FK CONSTRAINT; Schema: scores; Owner: gutenberg
--
ALTER TABLE ONLY scores.book_downloads
ADD CONSTRAINT "$1" FOREIGN KEY (fk_books) REFERENCES public.books(pk) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: also_downloads $1; Type: FK CONSTRAINT; Schema: scores; Owner: gutenberg
--
ALTER TABLE ONLY scores.also_downloads
ADD CONSTRAINT "$1" FOREIGN KEY (fk_books) REFERENCES public.books(pk) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: author_downloads author_downloads_fk_authors_fkey; Type: FK CONSTRAINT; Schema: scores; Owner: gutenberg
--
ALTER TABLE ONLY scores.author_downloads
ADD CONSTRAINT author_downloads_fk_authors_fkey FOREIGN KEY (fk_authors) REFERENCES public.authors(pk) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: bookshelf_downloads bookshelf_downloads_fk_bookshelves_fkey; Type: FK CONSTRAINT; Schema: scores; Owner: gutenberg
--
ALTER TABLE ONLY scores.bookshelf_downloads
ADD CONSTRAINT bookshelf_downloads_fk_bookshelves_fkey FOREIGN KEY (fk_bookshelves) REFERENCES public.bookshelves(pk) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: filetype_downloads filetype_downloads_fk_filetypes_fkey; Type: FK CONSTRAINT; Schema: scores; Owner: gutenberg
--
ALTER TABLE ONLY scores.filetype_downloads
ADD CONSTRAINT filetype_downloads_fk_filetypes_fkey FOREIGN KEY (fk_filetypes) REFERENCES public.filetypes(pk) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: subject_downloads subject_downloads_fk_subjects_fkey; Type: FK CONSTRAINT; Schema: scores; Owner: gutenberg
--
ALTER TABLE ONLY scores.subject_downloads
ADD CONSTRAINT subject_downloads_fk_subjects_fkey FOREIGN KEY (fk_subjects) REFERENCES public.subjects(pk);
--
-- Name: SCHEMA scores; Type: ACL; Schema: -; Owner: gutenberg
--
GRANT USAGE ON SCHEMA scores TO backupuser;
--
-- Name: TABLE also_downloads; Type: ACL; Schema: scores; Owner: gutenberg
--
GRANT SELECT ON TABLE scores.also_downloads TO backupuser;
--
-- Name: SEQUENCE also_downloads_id_seq; Type: ACL; Schema: scores; Owner: gutenberg
--
GRANT SELECT ON SEQUENCE scores.also_downloads_id_seq TO backupuser;
--
-- Name: TABLE author_downloads; Type: ACL; Schema: scores; Owner: gutenberg
--
GRANT SELECT ON TABLE scores.author_downloads TO backupuser;
--
-- Name: TABLE book_downloads; Type: ACL; Schema: scores; Owner: gutenberg
--
GRANT SELECT ON TABLE scores.book_downloads TO backupuser;
--
-- Name: SEQUENCE book_downloads_pk_seq; Type: ACL; Schema: scores; Owner: gutenberg
--
GRANT SELECT ON SEQUENCE scores.book_downloads_pk_seq TO backupuser;
--
-- Name: TABLE bookshelf_downloads; Type: ACL; Schema: scores; Owner: gutenberg
--
GRANT SELECT ON TABLE scores.bookshelf_downloads TO backupuser;
--
-- Name: TABLE file_downloads; Type: ACL; Schema: scores; Owner: gutenberg
--
GRANT SELECT ON TABLE scores.file_downloads TO backupuser;
--
-- Name: SEQUENCE file_downloads_pk_seq; Type: ACL; Schema: scores; Owner: gutenberg
--
GRANT SELECT ON SEQUENCE scores.file_downloads_pk_seq TO backupuser;
--
-- Name: TABLE filetype_downloads; Type: ACL; Schema: scores; Owner: gutenberg
--
GRANT SELECT ON TABLE scores.filetype_downloads TO backupuser;
--
-- Name: TABLE subject_downloads; Type: ACL; Schema: scores; Owner: gutenberg
--
GRANT SELECT ON TABLE scores.subject_downloads TO backupuser;
--
-- Name: TABLE v_by_filetype; Type: ACL; Schema: scores; Owner: gutenberg
--
GRANT SELECT ON TABLE scores.v_by_filetype TO backupuser;
--
-- Name: DEFAULT PRIVILEGES FOR SEQUENCES; Type: DEFAULT ACL; Schema: scores; Owner: postgres
--
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA scores REVOKE ALL ON SEQUENCES FROM postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA scores GRANT ALL ON SEQUENCES TO gutenberg;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA scores GRANT SELECT ON SEQUENCES TO backupuser;
--
-- Name: DEFAULT PRIVILEGES FOR TABLES; Type: DEFAULT ACL; Schema: scores; Owner: postgres
--
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA scores REVOKE ALL ON TABLES FROM postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA scores GRANT ALL ON TABLES TO gutenberg;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA scores GRANT SELECT ON TABLES TO backupuser;
--
-- PostgreSQL database dump complete
--