forked from NatLibFi/simplestats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_schema.sql
71 lines (59 loc) · 1.84 KB
/
database_schema.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
CREATE TABLE community (
community_id integer PRIMARY KEY,
name text,
handle character varying(256),
n_items integer,
n_bitstreams integer,
n_bytes bigint
);
CREATE TABLE collection (
collection_id integer PRIMARY KEY,
name text,
handle character varying(256),
n_items integer,
n_bitstreams integer,
n_bytes bigint
);
CREATE TABLE item (
item_id integer PRIMARY KEY,
name text,
handle character varying(256),
n_items integer,
n_bitstreams integer,
n_bytes bigint
);
CREATE TABLE community2community (
parent_comm_id integer REFERENCES community(community_id),
child_comm_id integer REFERENCES community(community_id)
);
CREATE TABLE community2collection (
community_id integer REFERENCES community(community_id),
collection_id integer REFERENCES collection(collection_id)
);
CREATE TABLE collection2item (
collection_id integer REFERENCES collection(collection_id),
item_id integer REFERENCES item(item_id)
);
CREATE TABLE downloadspercommunity (
community_id integer REFERENCES community(community_id),
"time" integer NOT NULL,
count integer DEFAULT 0 NOT NULL,
PRIMARY KEY(community_id, "time")
);
CREATE TABLE downloadspercollection (
collection_id integer REFERENCES collection(collection_id),
"time" integer NOT NULL,
count integer DEFAULT 0 NOT NULL,
PRIMARY KEY(collection_id, "time")
);
CREATE TABLE downloadsperitem (
item_id integer REFERENCES item(item_id),
"time" integer NOT NULL,
count integer DEFAULT 0 NOT NULL,
PRIMARY KEY(item_id, "time")
);
-- This *might* make things faster.
CREATE INDEX downloadsperitem_count_idx ON downloadsperitem (count);
CREATE index item_handle_idx ON item (handle);
CREATE index collection_handle_idx ON collection (handle);
CREATE index community_handle_idx ON community (handle);