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.' ;
0 commit comments