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>(), correctAnswer: jsonb('correct_answer').$type().notNull(), explanation: text('explanation').notNull(), userAnswer: jsonb('user_answer').$type(), isCorrect: boolean('is_correct'), answeredAt: timestamp('answered_at', { withTimezone: true }), }); export type TestQuestion = typeof testQuestions.$inferSelect; export type NewTestQuestion = typeof testQuestions.$inferInsert;