forked from NoahSaso/cloudflare-worker-cosmos-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.sql
58 lines (53 loc) · 1.64 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
-- Survey
DROP TABLE IF EXISTS surveys;
CREATE TABLE surveys (
id INTEGER PRIMARY KEY AUTOINCREMENT,
uuid TEXT NOT NULL,
dao TEXT NOT NULL,
name TEXT NOT NULL,
contributionsOpenAt DATETIME NOT NULL,
contributionsCloseRatingsOpenAt DATETIME NOT NULL,
ratingsCloseAt DATETIME NOT NULL,
contributionInstructions TEXT NOT NULL,
ratingInstructions TEXT NOT NULL,
attributesJson TEXT NOT NULL,
proposalId TEXT,
createdAtBlockHeight INTEGER NOT NULL,
createdAt DATETIME NOT NULL,
updatedAt DATETIME NOT NULL
);
-- Contribution
DROP TABLE IF EXISTS contributions;
CREATE TABLE contributions (
contributionId INTEGER PRIMARY KEY AUTOINCREMENT,
surveyId INTEGER NOT NULL,
contributorPublicKey TEXT NOT NULL,
nominatedByPublicKey TEXT,
content TEXT NOT NULL,
filesJson TEXT,
ratingsJson TEXT,
createdAt DATETIME NOT NULL,
updatedAt DATETIME NOT NULL,
CONSTRAINT fk_surveys FOREIGN KEY (surveyId) REFERENCES surveys (id),
CONSTRAINT unique_survey_contributor UNIQUE (surveyId, contributorPublicKey)
);
-- Rating
DROP TABLE IF EXISTS ratings;
CREATE TABLE ratings (
ratingId INTEGER PRIMARY KEY AUTOINCREMENT,
surveyId INTEGER NOT NULL,
contributionId INTEGER NOT NULL,
attributeIndex INTEGER NOT NULL,
raterPublicKey TEXT NOT NULL,
rating INTEGER,
createdAt DATETIME NOT NULL,
updatedAt DATETIME NOT NULL,
CONSTRAINT fk_surveys FOREIGN KEY (surveyId) REFERENCES surveys (id),
CONSTRAINT fk_contributions FOREIGN KEY (contributionId) REFERENCES contributions (contributionId),
CONSTRAINT unique_survey_contribution_rater_attribute UNIQUE (
surveyId,
contributionId,
attributeIndex,
raterPublicKey
)
);