-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
108 lines (98 loc) · 3.22 KB
/
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
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
create table if not exists polls (
id integer primary key,
created_at date default current_timestamp,
title text not null,
description text not null,
duration integer default null
);
create table if not exists lists (
id integer primary key,
created_at date default current_timestamp,
description text not null,
title text not null,
webhook_url text not null default ""
);
create table if not exists list_entries (
list_id integer not null,
cap_slug text not null,
foreign key (list_id) references lists(id),
foreign key (cap_slug) references caps(cap_slug)
);
create table if not exists caps (
cap_slug text primary key,
kind integer not null,
poll_id integer,
list_id integer,
ballot_id integer,
doc_id integer,
foreign key (poll_id) references polls(id),
foreign key (list_id) references lists(id),
foreign key (ballot_id) references ballots(id),
foreign key (doc_id) references docs(id),
constraint "Exactly one foreign key" check (
(not poll_id is null and list_id is null and ballot_id is null and doc_id is null) or
(poll_id is null and not list_id is null and ballot_id is null and doc_id is null) or
(poll_id is null and list_id is null and not ballot_id is null and doc_id is null) or
(poll_id is null and list_id is null and ballot_id is null and not doc_id is null)
)
);
create table if not exists votes (
kind integer not null,
username text not null,
password text not null,
created_at date default current_timestamp,
reason text,
poll_id integer not null,
foreign key (poll_id) references polls(id)
);
create table if not exists ballots (
id integer primary key,
created_at date default current_timestamp,
title text not null,
candidates text not null,
duration integer default null,
cached_result text not null,
hide_names bool not null,
description text not null
);
create table if not exists ballot_votes (
ballot_id integer not null,
created_at date default current_timestamp,
username text not null,
password text not null,
preferences text not null,
foreign key (ballot_id) references ballots(id)
);
create table if not exists docs (
id integer primary key,
created_at date default current_timestamp,
title text not null
);
create table if not exists doc_users (
doc_id integer not null,
username text not null,
password text not null,
foreign key (doc_id) references docs(id),
constraint "unique usernames" unique(doc_id, username)
);
create table if not exists doc_revisions (
id integer not null,
doc_id integer not null,
created_at date default current_timestamp,
username text not null,
comment text not null,
revision_diff text,
parent_revision_id integer,
foreign key (doc_id) references docs(id),
foreign key (doc_id, parent_revision_id) references doc_revisions(doc_id, id),
foreign key (doc_id, username) references doc_users(doc_id, username),
constraint "unique revision ids" unique(doc_id, id)
);
create table if not exists doc_revision_reactions (
doc_id integer not null,
revision_id integer not null,
username text not null,
kind integer not null,
foreign key(doc_id, revision_id) references doc_revisions(doc_id, id),
foreign key(doc_id, username) references doc_users(doc_id, username)
);