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.user_id IS ' The user ID this subscription belongs to.' ;
31
+ COMMENT ON COLUMN subscription.event_id IS ' The event ID this subscription belongs to.' ;
32
+
33
+ COMMENT ON COLUMN subscription.role IS
34
+ ' This field describes the role of the user for this subscription.
35
+ Possible values:
36
+ 0: For LV0 Community Reviewers
37
+ 1: For LV1 Community Reviewers
38
+ 2: For LV2 Moderators' ;
39
+
40
+ COMMENT ON COLUMN subscription.extra IS
41
+ ' This field is used to store all meta information about a subscription.
42
+ Specifically:
43
+
44
+ anonymous_id: str,
45
+ subscription_date: datetime,
46
+ preferred_categories: [int],
47
+ reward_address: str
48
+ ' ;
49
+
50
+
51
+ -- Allocation - Defines the relationship between users and proposals or proposals_reviews
52
+ -- to describe:
53
+ -- - the ownership of a proposal.
54
+ -- - the allocation of the reviews that needs to be done.
55
+ -- - the allocation of moderations that needs to be done.
56
+
57
+ CREATE TABLE allocation (
58
+ row_id SERIAL PRIMARY KEY ,
59
+ proposal_id INTEGER NULL ,
60
+ review_id INTEGER NULL ,
61
+ user_id INTEGER NOT NULL ,
62
+ type INTEGER NOT NULL ,
63
+
64
+ FOREIGN KEY (proposal_id) REFERENCES proposal(row_id) ON DELETE CASCADE ,
65
+ FOREIGN KEY (review_id) REFERENCES proposal_review(row_id) ON DELETE CASCADE ,
66
+ FOREIGN KEY (user_id) REFERENCES catalyst_user(row_id) ON DELETE CASCADE
67
+ );
68
+
69
+
70
+ COMMENT ON TABLE allocation IS ' The relationship between users and proposals or proposals_reviews.' ;
71
+ COMMENT ON COLUMN allocation.row_id IS ' Synthetic ID of this relationship.' ;
72
+ COMMENT ON COLUMN allocation.proposal_id IS ' The proposal ID the relationship belongs to.' ;
73
+ COMMENT ON COLUMN allocation.review_id IS ' The review ID the relationship belongs to.' ;
74
+ COMMENT ON COLUMN allocation.user_id IS ' The user ID the relationship belongs to.' ;
75
+ COMMENT ON COLUMN allocation.type IS ' The type of relationship stored.
76
+ Possible values:
77
+ 0: proposal ownership relation. proposal_id and user_id are required
78
+ 1: proposal allocated for review. proposal_id and user_id are required
79
+ 2: review allocated for moderation. review_id and user_id are required' ;
80
+
81
+ CREATE INDEX idx_allocation_proposal_type ON allocation(proposal_id, type) WHERE proposal_id IS NOT NULL ;
82
+ CREATE INDEX idx_allocation_review_type ON allocation(review_id, type) WHERE review_id IS NOT NULL ;
83
+ CREATE INDEX idx_allocation_user_type ON allocation(user_id, type);
84
+
85
+
86
+ -- Moderation - Defines the moderation submitted by users for each proposal_review.
87
+
88
+ CREATE TABLE moderation (
89
+ row_id SERIAL PRIMARY KEY ,
90
+ review_id INTEGER NOT NULL ,
91
+ user_id INTEGER NOT NULL ,
92
+ classification INTEGER NOT NULL ,
93
+ rationale VARCHAR ,
94
+ UNIQUE (review_id, user_id),
95
+
96
+ FOREIGN KEY (review_id) REFERENCES proposal_review(row_id) ON DELETE CASCADE ,
97
+ FOREIGN KEY (user_id) REFERENCES catalyst_user(row_id) ON DELETE CASCADE
98
+ );
99
+
100
+
101
+ COMMENT ON TABLE moderation IS ' An individual moderation for a proposal review.' ;
102
+ COMMENT ON COLUMN moderation.row_id IS ' Synthetic ID of this moderation.' ;
103
+ COMMENT ON COLUMN moderation.review_id IS ' The review ID the moderation belongs to.' ;
104
+ COMMENT ON COLUMN moderation.user_id IS ' The user ID the moderation belongs to.' ;
105
+ COMMENT ON COLUMN moderation.classification IS ' The value used to describe the moderation (e.g. 0: excluded, 1: included).' ;
106
+ COMMENT ON COLUMN moderation.rationale IS ' The rationale for the given classification.' ;
0 commit comments