feat: add tests and test_questions schema
Made-with: Cursor
This commit is contained in:
@@ -2,3 +2,5 @@ export * from './enums.js';
|
||||
export * from './users.js';
|
||||
export * from './sessions.js';
|
||||
export * from './subscriptions.js';
|
||||
export * from './tests.js';
|
||||
export * from './testQuestions.js';
|
||||
|
||||
25
src/db/schema/testQuestions.ts
Normal file
25
src/db/schema/testQuestions.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { pgTable, uuid, text, integer, boolean, timestamp } from 'drizzle-orm/pg-core';
|
||||
import { jsonb } from 'drizzle-orm/pg-core';
|
||||
import { questionTypeEnum } from './enums.js';
|
||||
import { tests } from './tests.js';
|
||||
import { questionBank } from './questionBank.js';
|
||||
|
||||
export const testQuestions = pgTable('test_questions', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
testId: uuid('test_id')
|
||||
.notNull()
|
||||
.references(() => tests.id, { onDelete: 'cascade' }),
|
||||
questionBankId: uuid('question_bank_id').references(() => questionBank.id, { onDelete: 'set null' }),
|
||||
orderNumber: integer('order_number').notNull(),
|
||||
type: questionTypeEnum('type').notNull(),
|
||||
questionText: text('question_text').notNull(),
|
||||
options: jsonb('options').$type<Array<{ key: string; text: string }>>(),
|
||||
correctAnswer: jsonb('correct_answer').$type<string | string[]>().notNull(),
|
||||
explanation: text('explanation').notNull(),
|
||||
userAnswer: jsonb('user_answer').$type<string | string[]>(),
|
||||
isCorrect: boolean('is_correct'),
|
||||
answeredAt: timestamp('answered_at', { withTimezone: true }),
|
||||
});
|
||||
|
||||
export type TestQuestion = typeof testQuestions.$inferSelect;
|
||||
export type NewTestQuestion = typeof testQuestions.$inferInsert;
|
||||
22
src/db/schema/tests.ts
Normal file
22
src/db/schema/tests.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { pgTable, uuid, integer, timestamp } from 'drizzle-orm/pg-core';
|
||||
import { stackEnum, levelEnum, testModeEnum, testStatusEnum } from './enums.js';
|
||||
import { users } from './users.js';
|
||||
|
||||
export const tests = pgTable('tests', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
userId: uuid('user_id')
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: 'cascade' }),
|
||||
stack: stackEnum('stack').notNull(),
|
||||
level: levelEnum('level').notNull(),
|
||||
questionCount: integer('question_count').notNull(),
|
||||
mode: testModeEnum('mode').notNull().default('fixed'),
|
||||
status: testStatusEnum('status').notNull().default('in_progress'),
|
||||
score: integer('score'),
|
||||
startedAt: timestamp('started_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
finishedAt: timestamp('finished_at', { withTimezone: true }),
|
||||
timeLimitSeconds: integer('time_limit_seconds'),
|
||||
});
|
||||
|
||||
export type Test = typeof tests.$inferSelect;
|
||||
export type NewTest = typeof tests.$inferInsert;
|
||||
Reference in New Issue
Block a user