Skip to content

Commit 173da29

Browse files
committed
feat: New schema for reviews backend.
1 parent 5312962 commit 173da29

9 files changed

+180
-44
lines changed
File renamed without changes.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
-- Catalyst Event Database
2+
3+
-- Subscription Table
4+
-- This table stores the subscriptions for users in the reviews module
5+
6+
CREATE TABLE subscription
7+
(
8+
row_id SERIAL PRIMARY KEY,
9+
user_id INTEGER NOT NULL,
10+
event_id INTEGER NOT NULL,
11+
role INTEGER NOT NULL,
12+
status INTEGER NOT NULL,
13+
extra JSONB NULL,
14+
15+
FOREIGN KEY (user_id) REFERENCES catalyst_user(row_id) ON DELETE CASCADE,
16+
FOREIGN KEY (event_id) REFERENCES event(row_id) ON DELETE CASCADE
17+
);
18+
19+
CREATE UNIQUE INDEX subscription_idx ON subscription(user_id,event_id,role);
20+
21+
COMMENT ON TABLE subscription IS '
22+
A subscription describes the possible roles of a single user for an event.
23+
A user can participate in multiple events active as multiple roles.
24+
For this reason this dedicated table tracks all active roles for a user related
25+
to a specific event and stores meta information about them.
26+
Some of these subscriptions will be automatically created by the system.
27+
The presence/status of subscriptions will determine user capabilities in the app.
28+
';
29+
30+
COMMENT ON COLUMN subscription.role IS
31+
'This field describes the role of the user for this subscription.
32+
Possible values:
33+
0: For LV0 Community Reviewers
34+
1: For LV1 Community Reviewers
35+
2: For LV2 Moderators';
36+
37+
COMMENT ON COLUMN subscription.extra IS
38+
'This field is used to store all meta information about a subscription.
39+
Specifically:
40+
41+
anonymous_id: str,
42+
subscription_date: datetime,
43+
preferred_categories: [int]
44+
';
45+
46+
47+
-- Allocation - Defines the relationship between users and proposals or proposals_reviews
48+
-- to describe:
49+
-- - the ownership of a proposal.
50+
-- - the allocation of the reviews that needs to be done.
51+
-- - the allocation of moderations that needs to be done.
52+
53+
CREATE TABLE allocation (
54+
row_id SERIAL PRIMARY KEY,
55+
proposal_id INTEGER NULL,
56+
review_id INTEGER NULL,
57+
user_id INTEGER NOT NULL,
58+
type INTEGER NOT NULL,
59+
60+
FOREIGN KEY (proposal_id) REFERENCES proposal(row_id) ON DELETE CASCADE,
61+
FOREIGN KEY (review_id) REFERENCES proposal_review(row_id) ON DELETE CASCADE,
62+
FOREIGN KEY (user_id) REFERENCES catalyst_user(row_id) ON DELETE CASCADE
63+
);
64+
65+
66+
COMMENT ON TABLE allocation IS 'The relationship between users and proposals or proposals_reviews.';
67+
COMMENT ON COLUMN allocation.row_id IS 'Synthetic ID of this relationship.';
68+
COMMENT ON COLUMN allocation.proposal_id IS 'The proposal the relationship is related to.';
69+
COMMENT ON COLUMN allocation.review_id IS 'The review the relationship is related to.';
70+
COMMENT ON COLUMN allocation.user_id IS 'The user the relationship is related to.';
71+
COMMENT ON COLUMN allocation.type IS 'The type of relationship stored.
72+
Possible values:
73+
0: proposal ownership relation. proposal_id and user_id are required
74+
1: proposal allocated for review. proposal_id and user_id are required
75+
2: review allocated for moderation. review_id and user_id are required';
76+
77+
CREATE INDEX idx_allocation_proposal_type ON allocation(proposal_id, type) WHERE proposal_id IS NOT NULL;
78+
CREATE INDEX idx_allocation_review_type ON allocation(review_id, type) WHERE review_id IS NOT NULL;
79+
CREATE INDEX idx_allocation_user_type ON allocation(user_id, type);
80+
81+
82+
-- Moderation - Defines the moderation submitted by users for each proposal_review.
83+
84+
CREATE TABLE moderation (
85+
row_id SERIAL PRIMARY KEY,
86+
review_id INTEGER NOT NULL,
87+
user_id INTEGER NOT NULL,
88+
classification INTEGER NOT NULL,
89+
rationale VARCHAR,
90+
UNIQUE (review_id, user_id),
91+
92+
FOREIGN KEY (review_id) REFERENCES proposal_review(row_id) ON DELETE CASCADE,
93+
FOREIGN KEY (user_id) REFERENCES catalyst_user(row_id) ON DELETE CASCADE
94+
);
95+
96+
97+
COMMENT ON TABLE moderation IS 'An individual moderation for a proposal review.';
98+
COMMENT ON COLUMN moderation.row_id IS 'Synthetic ID of this moderation.';
99+
COMMENT ON COLUMN moderation.review_id IS 'The review the moderation is related to.';
100+
COMMENT ON COLUMN moderation.user_id IS 'The user the moderation is submitted from.';
101+
COMMENT ON COLUMN moderation.classification IS 'The value used to describe the moderation (e.g. 0: excluded, 1: included).';
102+
COMMENT ON COLUMN moderation.rationale IS 'The rationale for the given classification.';
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- Catalyst Event Database
2+
3+
-- Catalyst ID map Table
4+
-- This table stores the relationship between a catalyst ID and an email address.
5+
6+
CREATE TABLE catalyst_id_map
7+
(
8+
row_id SERIAL PRIMARY KEY,
9+
catalyst_id VARCHAR NOT NULL,
10+
email VARCHAR NOT NULL,
11+
signed_email VARCHAR NOT NULL,
12+
status INTEGER NOT NULL,
13+
confirmation_token VARCHAR NOT NULL,
14+
15+
UNIQUE(catalyst_id)
16+
);
17+
18+
CREATE UNIQUE INDEX catalyst_id_idx ON catalyst_id_map(catalyst_id, email);
19+
20+
COMMENT ON COLUMN catalyst_id_map.email IS 'The email is stored encrypted.';
21+
COMMENT ON COLUMN catalyst_id_map.status IS '
22+
Describes the status of an account:
23+
0: Inactive
24+
1: Active
25+
2: Banned.';
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
-- Catalyst Event Database
2+
3+
-- User Table
4+
-- This table stores the users for the reviews module
5+
6+
CREATE TABLE catalyst_user
7+
(
8+
row_id SERIAL PRIMARY KEY,
9+
catalyst_id INTEGER NOT NULL,
10+
enc_password VARCHAR NOT NULL,
11+
salt VARCHAR NOT NULL,
12+
extra JSONB NULL,
13+
14+
FOREIGN KEY(catalyst_id) REFERENCES catalyst_id_map(row_id) ON DELETE CASCADE
15+
);
16+
17+
CREATE UNIQUE INDEX user_catalyst_id_idx ON catalyst_user(catalyst_id);
18+
19+
20+
COMMENT ON COLUMN catalyst_user.extra IS
21+
'This field is used to store all meta information about a user that
22+
are required by the application. Specifically:
23+
24+
admin: bool,
25+
username: str,
26+
registration_date: datetime,
27+
due_diligence: {
28+
status: int,
29+
due_diligence_id: str,
30+
url: str
31+
},
32+
historic_stats: {
33+
"reviews": {
34+
"active_funds": int,
35+
"submitted": int,
36+
"blank": int,
37+
"valid": int
38+
},
39+
"moderations": {
40+
"active_funds": int,
41+
"submitted": int,
42+
"allocated": int,
43+
}
44+
}
45+
';

src/event-db/migrations/V4__proposal_tables.sql renamed to src/event-db/migrations/V6__proposal_tables.sql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ COMMENT ON COLUMN reviewer_level.event_id IS 'The specific Event ID this review
9999
CREATE TABLE proposal_review (
100100
row_id SERIAL PRIMARY KEY,
101101
proposal_id INTEGER NOT NULL,
102+
user_id INTEGER NOT NULL,
102103
assessor VARCHAR NOT NULL,
103104
assessor_level INTEGER,
104105
reward_address TEXT,
@@ -111,11 +112,12 @@ CREATE TABLE proposal_review (
111112
feasibility_note VARCHAR,
112113
auditability_rating_given INTEGER,
113114
auditability_note VARCHAR,
115+
allocated INTEGER,
114116
ranking INTEGER,
115117
flags JSONB NULL,
116118

117-
FOREIGN KEY (proposal_id) REFERENCES proposal(row_id) ON DELETE CASCADE,
118-
FOREIGN KEY (assessor_level) REFERENCES reviewer_level(row_id) ON DELETE CASCADE
119+
FOREIGN KEY (user_id) REFERENCES catalyst_user(row_id) ON DELETE SET NULL,
120+
FOREIGN KEY (proposal_id) REFERENCES proposal(row_id) ON DELETE CASCADE
119121
);
120122

121123
COMMENT ON TABLE proposal_review IS 'All Reviews.';
@@ -146,6 +148,10 @@ COMMENT ON COLUMN proposal_review.auditability_note IS
146148
'A note about the auditability rating given.
147149
DEPRECATED: Only used for Vit-SS compatibility.';
148150

151+
COMMENT ON COLUMN proposal_review.allocated IS
152+
'Describes if the review was part of the original reviewer allocation.
153+
';
154+
149155
COMMENT ON COLUMN proposal_review.ranking IS
150156
'Numeric Measure of quality of this review according to veteran community advisors.
151157
DEPRECATED: Only used for Vit-SS compatibility.
File renamed without changes.
File renamed without changes.

src/event-db/migrations/V9__moderation_stage.sql

Lines changed: 0 additions & 42 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)