feat: add question bank schema
Made-with: Cursor
This commit is contained in:
@@ -4,3 +4,6 @@ export * from './sessions.js';
|
|||||||
export * from './subscriptions.js';
|
export * from './subscriptions.js';
|
||||||
export * from './tests.js';
|
export * from './tests.js';
|
||||||
export * from './testQuestions.js';
|
export * from './testQuestions.js';
|
||||||
|
export * from './questionBank.js';
|
||||||
|
export * from './questionCacheMeta.js';
|
||||||
|
export * from './questionReports.js';
|
||||||
|
|||||||
22
src/db/schema/questionBank.ts
Normal file
22
src/db/schema/questionBank.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { pgTable, uuid, text, integer, timestamp } from 'drizzle-orm/pg-core';
|
||||||
|
import { jsonb } from 'drizzle-orm/pg-core';
|
||||||
|
import { stackEnum, levelEnum, questionTypeEnum, questionStatusEnum, questionSourceEnum } from './enums.js';
|
||||||
|
|
||||||
|
export const questionBank = pgTable('question_bank', {
|
||||||
|
id: uuid('id').primaryKey().defaultRandom(),
|
||||||
|
stack: stackEnum('stack').notNull(),
|
||||||
|
level: levelEnum('level').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(),
|
||||||
|
status: questionStatusEnum('status').notNull().default('pending'),
|
||||||
|
source: questionSourceEnum('source').notNull(),
|
||||||
|
usageCount: integer('usage_count').notNull().default(0),
|
||||||
|
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||||
|
approvedAt: timestamp('approved_at', { withTimezone: true }),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type QuestionBank = typeof questionBank.$inferSelect;
|
||||||
|
export type NewQuestionBank = typeof questionBank.$inferInsert;
|
||||||
18
src/db/schema/questionCacheMeta.ts
Normal file
18
src/db/schema/questionCacheMeta.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { pgTable, uuid, varchar, integer, timestamp } from 'drizzle-orm/pg-core';
|
||||||
|
import { jsonb } from 'drizzle-orm/pg-core';
|
||||||
|
import { questionBank } from './questionBank.js';
|
||||||
|
|
||||||
|
export const questionCacheMeta = pgTable('question_cache_meta', {
|
||||||
|
id: uuid('id').primaryKey().defaultRandom(),
|
||||||
|
questionBankId: uuid('question_bank_id')
|
||||||
|
.notNull()
|
||||||
|
.references(() => questionBank.id, { onDelete: 'cascade' }),
|
||||||
|
llmModel: varchar('llm_model', { length: 100 }).notNull(),
|
||||||
|
promptHash: varchar('prompt_hash', { length: 64 }).notNull(),
|
||||||
|
generationTimeMs: integer('generation_time_ms').notNull(),
|
||||||
|
rawResponse: jsonb('raw_response').$type<unknown>(),
|
||||||
|
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type QuestionCacheMeta = typeof questionCacheMeta.$inferSelect;
|
||||||
|
export type NewQuestionCacheMeta = typeof questionCacheMeta.$inferInsert;
|
||||||
21
src/db/schema/questionReports.ts
Normal file
21
src/db/schema/questionReports.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { pgTable, uuid, text, timestamp } from 'drizzle-orm/pg-core';
|
||||||
|
import { reportStatusEnum } from './enums.js';
|
||||||
|
import { questionBank } from './questionBank.js';
|
||||||
|
import { users } from './users.js';
|
||||||
|
|
||||||
|
export const questionReports = pgTable('question_reports', {
|
||||||
|
id: uuid('id').primaryKey().defaultRandom(),
|
||||||
|
questionBankId: uuid('question_bank_id')
|
||||||
|
.notNull()
|
||||||
|
.references(() => questionBank.id, { onDelete: 'cascade' }),
|
||||||
|
userId: uuid('user_id')
|
||||||
|
.notNull()
|
||||||
|
.references(() => users.id, { onDelete: 'cascade' }),
|
||||||
|
reason: text('reason').notNull(),
|
||||||
|
status: reportStatusEnum('status').notNull().default('open'),
|
||||||
|
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||||
|
resolvedAt: timestamp('resolved_at', { withTimezone: true }),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type QuestionReport = typeof questionReports.$inferSelect;
|
||||||
|
export type NewQuestionReport = typeof questionReports.$inferInsert;
|
||||||
Reference in New Issue
Block a user