Skip to content

Commit 139490e

Browse files
committed
chore: Finalize Reviews DB schema.
1 parent 173da29 commit 139490e

File tree

4 files changed

+70
-49
lines changed

4 files changed

+70
-49
lines changed

src/event-db/migrations/V11__reviews.sql

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
CREATE TABLE subscription
77
(
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,
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,
1414

1515
FOREIGN KEY (user_id) REFERENCES catalyst_user(row_id) ON DELETE CASCADE,
1616
FOREIGN KEY (event_id) REFERENCES event(row_id) ON DELETE CASCADE
@@ -27,6 +27,9 @@ Some of these subscriptions will be automatically created by the system.
2727
The presence/status of subscriptions will determine user capabilities in the app.
2828
';
2929

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+
3033
COMMENT ON COLUMN subscription.role IS
3134
'This field describes the role of the user for this subscription.
3235
Possible values:
@@ -40,7 +43,8 @@ Specifically:
4043
4144
anonymous_id: str,
4245
subscription_date: datetime,
43-
preferred_categories: [int]
46+
preferred_categories: [int],
47+
reward_address: str
4448
';
4549

4650

@@ -51,11 +55,11 @@ preferred_categories: [int]
5155
-- - the allocation of moderations that needs to be done.
5256

5357
CREATE TABLE allocation (
54-
row_id SERIAL PRIMARY KEY,
58+
row_id SERIAL PRIMARY KEY,
5559
proposal_id INTEGER NULL,
56-
review_id INTEGER NULL,
57-
user_id INTEGER NOT NULL,
58-
type INTEGER NOT NULL,
60+
review_id INTEGER NULL,
61+
user_id INTEGER NOT NULL,
62+
type INTEGER NOT NULL,
5963

6064
FOREIGN KEY (proposal_id) REFERENCES proposal(row_id) ON DELETE CASCADE,
6165
FOREIGN KEY (review_id) REFERENCES proposal_review(row_id) ON DELETE CASCADE,
@@ -65,9 +69,9 @@ CREATE TABLE allocation (
6569

6670
COMMENT ON TABLE allocation IS 'The relationship between users and proposals or proposals_reviews.';
6771
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.';
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.';
7175
COMMENT ON COLUMN allocation.type IS 'The type of relationship stored.
7276
Possible values:
7377
0: proposal ownership relation. proposal_id and user_id are required
@@ -82,11 +86,11 @@ CREATE INDEX idx_allocation_user_type ON allocation(user_id, type);
8286
-- Moderation - Defines the moderation submitted by users for each proposal_review.
8387

8488
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,
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,
9094
UNIQUE (review_id, user_id),
9195

9296
FOREIGN KEY (review_id) REFERENCES proposal_review(row_id) ON DELETE CASCADE,
@@ -96,7 +100,7 @@ CREATE TABLE moderation (
96100

97101
COMMENT ON TABLE moderation IS 'An individual moderation for a proposal review.';
98102
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.';
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.';
101105
COMMENT ON COLUMN moderation.classification IS 'The value used to describe the moderation (e.g. 0: excluded, 1: included).';
102106
COMMENT ON COLUMN moderation.rationale IS 'The rationale for the given classification.';

src/event-db/migrations/V4__catalyst_id.sql

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,41 @@
55

66
CREATE TABLE catalyst_id_map
77
(
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,
8+
row_id SERIAL PRIMARY KEY,
9+
catalyst_id VARCHAR NOT NULL,
10+
email VARCHAR NOT NULL,
11+
username VARCHAR NOT NULL,
12+
signed_email VARCHAR NOT NULL,
13+
status INTEGER NOT NULL,
14+
confirmation_token VARCHAR,
15+
confirmation_requested_at TIMESTAMP,
16+
confirmed_at TIMESTAMP,
1417

1518
UNIQUE(catalyst_id)
1619
);
1720

1821
CREATE UNIQUE INDEX catalyst_id_idx ON catalyst_id_map(catalyst_id, email);
1922

20-
COMMENT ON COLUMN catalyst_id_map.email IS 'The email is stored encrypted.';
23+
COMMENT ON TABLE catalyst_id_map IS '
24+
The `catalyst_id_map` table is used to store the map between the CatalystID and email/username for each user.
25+
Because the Catalyst RBAC registration are stored on-chain, and for this reason are publicly accessible,
26+
sensitive information like email address will be stored in a centralized DB, keeping a reference to the CatalystID.
27+
The email address is stored only when its signature corresponds to the CatalystID.
28+
';
29+
COMMENT ON COLUMN catalyst_id_map.catalyst_id IS '
30+
It contains the unique part of the CatalystID.
31+
Given a full CatalystID like `id.catalyst://[email protected]/FftxFnOrj2qmTuB2oZG2v0YEWJfKvQ9Gg8AgNAhDsKE`
32+
The scheme and the username are omitted and only the unique part `preprod.cardano/FftxFnOrj2qmTuB2oZG2v0YEWJfKvQ9Gg8AgNAhDsKE`
33+
is stored in this field.
34+
';
35+
COMMENT ON COLUMN catalyst_id_map.email IS 'The email address stored in plaintext.';
36+
COMMENT ON COLUMN catalyst_id_map.username IS 'The username extracted from the CatalystID stored in plaintext.';
37+
COMMENT ON COLUMN catalyst_id_map.signed_email IS 'The signed document that includes the email address.';
2138
COMMENT ON COLUMN catalyst_id_map.status IS '
2239
Describes the status of an account:
2340
0: Inactive
2441
1: Active
25-
2: Banned.';
42+
2: Banned.';
43+
COMMENT ON COLUMN catalyst_id_map.confirmation_token IS 'The token that is generated for the email confirmation.';
44+
COMMENT ON COLUMN catalyst_id_map.confirmation_requested_at IS 'The timestamp to validate confirmation token validity.';
45+
COMMENT ON COLUMN catalyst_id_map.confirmed_at IS 'The timestamp of the email confirmation.';

src/event-db/migrations/V5__user.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ CREATE TABLE catalyst_user
1717
CREATE UNIQUE INDEX user_catalyst_id_idx ON catalyst_user(catalyst_id);
1818

1919

20+
COMMENT ON TABLE catalyst_user IS '
21+
This tables stores the user account for the Review Module.
22+
It contains a reference to the catalyst_id that is used as public and unique identifier.
23+
';
24+
25+
COMMENT ON COLUMN catalyst_user.catalyst_id IS 'The catalyst_id this account belongs to.';
26+
COMMENT ON COLUMN catalyst_user.enc_password IS 'The encrypted password.';
27+
COMMENT ON COLUMN catalyst_user.salt IS 'The salt for the password encryption.';
2028
COMMENT ON COLUMN catalyst_user.extra IS
2129
'This field is used to store all meta information about a user that
2230
are required by the application. Specifically:

src/event-db/migrations/V6__proposal_tables.sql

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ CREATE TABLE proposal_review (
102102
user_id INTEGER NOT NULL,
103103
assessor VARCHAR NOT NULL,
104104
assessor_level INTEGER,
105-
reward_address TEXT,
106105

107-
-- These fields are deprecated and WILL BE removed in a future migration.
108-
-- They MUST only be used for Vit-SS compatibility.
109106
impact_alignment_rating_given INTEGER,
110107
impact_alignment_note VARCHAR,
111108
feasibility_rating_given INTEGER,
@@ -122,31 +119,23 @@ CREATE TABLE proposal_review (
122119

123120
COMMENT ON TABLE proposal_review IS 'All Reviews.';
124121
COMMENT ON COLUMN proposal_review.row_id IS 'Synthetic Unique Key.';
125-
COMMENT ON COLUMN proposal_review.proposal_id IS 'The Proposal this review is for.';
126-
COMMENT ON COLUMN proposal_review.assessor IS 'Assessors Anonymized ID';
122+
COMMENT ON COLUMN proposal_review.proposal_id IS 'The Proposal id this review belongs to.';
123+
COMMENT ON COLUMN proposal_review.user_id IS 'The user id this review belongs to.';
124+
COMMENT ON COLUMN proposal_review.assessor IS 'Assessors Anonymized ID.';
127125
COMMENT ON COLUMN proposal_review.assessor_level IS 'Assessors level ID';
128-
COMMENT ON COLUMN proposal_review.reward_address IS 'Assessors reward address';
129126

130127
COMMENT ON COLUMN proposal_review.impact_alignment_rating_given IS
131-
'The numeric rating assigned to the proposal by the assessor.
132-
DEPRECATED: Only used for Vit-SS compatibility.';
128+
'The numeric rating assigned to the proposal by the assessor.';
133129
COMMENT ON COLUMN proposal_review.impact_alignment_note IS
134-
'A note about why the impact rating was given.
135-
DEPRECATED: Only used for Vit-SS compatibility.';
136-
130+
'A note about why the impact rating was given.';
137131
COMMENT ON COLUMN proposal_review.feasibility_rating_given IS
138-
'The numeric feasibility rating given.
139-
DEPRECATED: Only used for Vit-SS compatibility.';
132+
'The numeric feasibility rating given.';
140133
COMMENT ON COLUMN proposal_review.feasibility_note IS
141-
'A note about why the feasibility rating was given.
142-
DEPRECATED: Only used for Vit-SS compatibility.';
143-
134+
'A note about why the feasibility rating was given.';
144135
COMMENT ON COLUMN proposal_review.auditability_rating_given IS
145-
'The numeric auditability rating given.
146-
DEPRECATED: Only used for Vit-SS compatibility.';
136+
'The numeric auditability rating given.';
147137
COMMENT ON COLUMN proposal_review.auditability_note IS
148-
'A note about the auditability rating given.
149-
DEPRECATED: Only used for Vit-SS compatibility.';
138+
'A note about the auditability rating given.';
150139

151140
COMMENT ON COLUMN proposal_review.allocated IS
152141
'Describes if the review was part of the original reviewer allocation.

0 commit comments

Comments
 (0)