Skip to content

Commit e5df979

Browse files
committed
PEER-219: Update schema
Signed-off-by: SeeuSim <[email protected]>
1 parent a3aef71 commit e5df979

File tree

6 files changed

+14
-36
lines changed

6 files changed

+14
-36
lines changed
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
CREATE TABLE IF NOT EXISTS "question_attempts" (
22
"attempt_id" serial PRIMARY KEY NOT NULL,
33
"question_id" integer NOT NULL,
4-
"user_id_1" integer NOT NULL,
5-
"user_id_2" integer,
4+
"user_id_1" uuid NOT NULL,
5+
"user_id_2" uuid,
66
"code" text NOT NULL,
77
"timestamp" timestamp (6) with time zone DEFAULT now(),
8-
"language" varchar(50) NOT NULL,
9-
"topics" varchar(255)[] NOT NULL,
10-
"difficulty" varchar(50) NOT NULL
8+
"language" varchar(50) NOT NULL
119
);
1210
--> statement-breakpoint
1311
CREATE UNIQUE INDEX IF NOT EXISTS "unique_users_attempt" ON "question_attempts" USING btree ("question_id","user_id_1","user_id_2");

backend/question/drizzle/meta/0001_snapshot.json

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "7c021462-f400-4c5e-90a0-bf42f218e710",
2+
"id": "afa9ccaa-137c-47d3-acb0-ab1e2208038e",
33
"prevId": "84b2ca8d-3021-496f-8769-bbc4dada6468",
44
"version": "7",
55
"dialect": "postgresql",
@@ -53,13 +53,13 @@
5353
},
5454
"user_id_1": {
5555
"name": "user_id_1",
56-
"type": "integer",
56+
"type": "uuid",
5757
"primaryKey": false,
5858
"notNull": true
5959
},
6060
"user_id_2": {
6161
"name": "user_id_2",
62-
"type": "integer",
62+
"type": "uuid",
6363
"primaryKey": false,
6464
"notNull": false
6565
},
@@ -81,18 +81,6 @@
8181
"type": "varchar(50)",
8282
"primaryKey": false,
8383
"notNull": true
84-
},
85-
"topics": {
86-
"name": "topics",
87-
"type": "varchar(255)[]",
88-
"primaryKey": false,
89-
"notNull": true
90-
},
91-
"difficulty": {
92-
"name": "difficulty",
93-
"type": "varchar(50)",
94-
"primaryKey": false,
95-
"notNull": true
9684
}
9785
},
9886
"indexes": {

backend/question/drizzle/meta/_journal.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
{
1313
"idx": 1,
1414
"version": "7",
15-
"when": 1730355971431,
16-
"tag": "0001_brave_gauntlet",
15+
"when": 1730553826248,
16+
"tag": "0001_attempt_history",
1717
"breakpoints": true
1818
}
1919
]

backend/question/src/controller/attempted-controller.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { addAttempt } from '../services/post/addAttempt';
55
// Define the expected request body structure
66
interface AddAttemptRequestBody {
77
questionId: number;
8-
userId1: number;
9-
userId2?: number; // Optional if userId2 is not always required
8+
userId1: string;
9+
userId2?: string; // Optional if userId2 is not always required
1010
code: string;
1111
language: string;
1212
topic: string[]; // Assuming topic is an array of strings
@@ -33,8 +33,6 @@ export const createAttempt = async (
3333
userId2,
3434
code,
3535
language,
36-
topic: topic, // Adjusted to match the schema if topics is used
37-
difficulty,
3836
});
3937

4038
// Respond with success

backend/question/src/lib/db/schema.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ export const questionAttempts = pgTable(
2525
{
2626
attemptId: serial('attempt_id').primaryKey(),
2727
questionId: integer('question_id').notNull(),
28-
userId1: integer('user_id_1').notNull(),
29-
userId2: integer('user_id_2'), // Nullable if only one user is involved
28+
userId1: uuid('user_id_1').notNull(),
29+
userId2: uuid('user_id_2'), // Nullable if only one user is involved
3030
code: text('code').notNull(),
3131
timestamp: timestamp('timestamp', { precision: 6, withTimezone: true }).defaultNow(),
3232
language: varchar('language', { length: 50 }).notNull(),
33-
topic: varchar('topics', { length: 255 }).array().notNull(), // Denormalized array of topics
34-
difficulty: varchar('difficulty', { length: 50 }).notNull(),
3533
},
3634
(questAttempt) => ({
3735
uniqueUsersAttempt: uniqueIndex('unique_users_attempt').on(

backend/question/src/services/post/addAttempt.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ import { questionAttempts } from '@/lib/db/schema';
44
// Define the data structure for an attempt
55
interface AttemptData {
66
questionId: number;
7-
userId1: number;
8-
userId2?: number;
7+
userId1: string;
8+
userId2?: string;
99
code: string;
1010
language: string;
11-
topic: string[]; // Use `topic` to match the schema
12-
difficulty: string;
1311
}
1412

1513
// Function to add an attempt to the database
@@ -20,7 +18,5 @@ export const addAttempt = async (attemptData: AttemptData) => {
2018
userId2: attemptData.userId2,
2119
code: attemptData.code,
2220
language: attemptData.language,
23-
topic: attemptData.topic, // Assuming this matches the schema
24-
difficulty: attemptData.difficulty,
2521
});
2622
};

0 commit comments

Comments
 (0)