rogasper commited on
Commit
ef46e44
·
1 Parent(s): d0190d5

feat: add db:seed command to package.json and update README.md for seeding reference data. Enhance job status handling in generation logic to support completed_partial status, improving error reporting and user feedback. Introduce new utility functions for job outcome resolution and non-retryable error detection, along with corresponding tests. Update database migration scripts to include new tables and fields for improved data management.

Browse files
README.md CHANGED
@@ -151,7 +151,7 @@ bun run db:push
151
  Optionally seed reference data (exam types, sections):
152
 
153
  ```bash
154
- cd packages/db && bun run db:seed
155
  ```
156
 
157
  ### 5. Run the dev servers
@@ -218,6 +218,7 @@ Run from the **repository root**:
218
  | `bun run db:push` | Push Drizzle schema to PostgreSQL |
219
  | `bun run db:generate` | Generate migration files |
220
  | `bun run db:migrate` | Run migrations |
 
221
  | `bun run db:studio` | Open Drizzle Studio |
222
  | `bun run db:start` | Start PostgreSQL + Redis (Docker Compose) |
223
  | `bun run db:stop` | Stop Docker Compose services |
 
151
  Optionally seed reference data (exam types, sections):
152
 
153
  ```bash
154
+ bun run db:seed
155
  ```
156
 
157
  ### 5. Run the dev servers
 
218
  | `bun run db:push` | Push Drizzle schema to PostgreSQL |
219
  | `bun run db:generate` | Generate migration files |
220
  | `bun run db:migrate` | Run migrations |
221
+ | `bun run db:seed` | Seed reference data (exam types, sections) |
222
  | `bun run db:studio` | Open Drizzle Studio |
223
  | `bun run db:start` | Start PostgreSQL + Redis (Docker Compose) |
224
  | `bun run db:stop` | Stop Docker Compose services |
apps/web/src/components/generate/GlobalGenerationProgress.tsx CHANGED
@@ -4,6 +4,7 @@ import { useMutation } from "@tanstack/react-query";
4
  import { Button } from "@labas/ui/components/button";
5
  import { MaterialIcon } from "@/components/ui/MaterialIcon";
6
  import { useGenerationJobs, type ActiveJob } from "@/hooks/use-generation-jobs";
 
7
  import { trpc, queryClient } from "@/utils/trpc";
8
 
9
  interface LogEntry {
@@ -196,7 +197,7 @@ function SingleJobCard({
196
  </div>
197
  </div>
198
 
199
- {isAgentic && <TerminalLog logs={logs} isRunning={job.status !== "completed"} />}
200
  </div>
201
  );
202
  }
 
4
  import { Button } from "@labas/ui/components/button";
5
  import { MaterialIcon } from "@/components/ui/MaterialIcon";
6
  import { useGenerationJobs, type ActiveJob } from "@/hooks/use-generation-jobs";
7
+ import { isTerminal } from "@/hooks/use-job-shared";
8
  import { trpc, queryClient } from "@/utils/trpc";
9
 
10
  interface LogEntry {
 
197
  </div>
198
  </div>
199
 
200
+ {isAgentic && <TerminalLog logs={logs} isRunning={!isTerminal(job.status)} />}
201
  </div>
202
  );
203
  }
apps/web/src/hooks/use-generation-jobs.ts CHANGED
@@ -75,9 +75,12 @@ export function useGenerationJobs() {
75
  );
76
 
77
  if (alreadyCompleted) {
78
- if (status === "completed" && data.resultJson) {
79
  setResult(baseResult);
80
  }
 
 
 
81
  return;
82
  }
83
 
@@ -87,6 +90,13 @@ export function useGenerationJobs() {
87
  }
88
  }
89
 
 
 
 
 
 
 
 
90
  if (status === "completed" && data.resultJson) {
91
  setResult(baseResult);
92
  }
 
75
  );
76
 
77
  if (alreadyCompleted) {
78
+ if ((status === "completed" || status === "completed_partial") && data.resultJson) {
79
  setResult(baseResult);
80
  }
81
+ if (status === "completed_partial" && data.errorMessage) {
82
+ setError(data.errorMessage as string);
83
+ }
84
  return;
85
  }
86
 
 
90
  }
91
  }
92
 
93
+ if (status === "completed_partial" && data.resultJson) {
94
+ setResult(baseResult);
95
+ if (data.errorMessage) {
96
+ setError(data.errorMessage as string);
97
+ }
98
+ }
99
+
100
  if (status === "completed" && data.resultJson) {
101
  setResult(baseResult);
102
  }
apps/web/src/hooks/use-job-shared.ts CHANGED
@@ -59,7 +59,7 @@ export const ACTIVE_STATUSES = new Set([
59
  "running_quality",
60
  ]);
61
 
62
- export const TERMINAL_STATUSES = new Set(["completed", "failed", "cancelled"]);
63
 
64
  export function isTerminal(status: string): boolean {
65
  return TERMINAL_STATUSES.has(status);
 
59
  "running_quality",
60
  ]);
61
 
62
+ export const TERMINAL_STATUSES = new Set(["completed", "completed_partial", "failed", "cancelled"]);
63
 
64
  export function isTerminal(status: string): boolean {
65
  return TERMINAL_STATUSES.has(status);
apps/web/src/routes/__root.tsx CHANGED
@@ -94,12 +94,12 @@ function RootComponent() {
94
  <GlobalGenerationProgress />
95
  <Toaster richColors />
96
  </ThemeProvider>
97
- {/* {import.meta.env.DEV && (
98
  <>
99
  <TanStackRouterDevtools position="bottom-left" />
100
  <ReactQueryDevtools position="bottom" buttonPosition="bottom-right" />
101
  </>
102
- )} */}
103
  </>
104
  );
105
  }
 
94
  <GlobalGenerationProgress />
95
  <Toaster richColors />
96
  </ThemeProvider>
97
+ {import.meta.env.DEV && (
98
  <>
99
  <TanStackRouterDevtools position="bottom-left" />
100
  <ReactQueryDevtools position="bottom" buttonPosition="bottom-right" />
101
  </>
102
+ )}
103
  </>
104
  );
105
  }
apps/web/src/routes/admin.jobs.tsx CHANGED
@@ -8,7 +8,7 @@ import { getErrorMessage } from "@/lib/error-utils";
8
  import { DataTable } from "@/components/admin/DataTable";
9
  import type { ColumnDef } from "@/components/admin/DataTable";
10
 
11
- const STATUSES = ["all", "pending", "running", "completed", "failed", "cancelled"] as const;
12
 
13
  export const Route = createFileRoute("/admin/jobs")({
14
  component: AdminJobs,
@@ -87,6 +87,7 @@ function AdminJobs() {
87
  cell: ({ row }) => (
88
  <span className={`text-xs font-semibold px-2 py-0.5 rounded-full ${
89
  row.status === "completed" ? "bg-[var(--matcha-300)] text-[var(--matcha-800)]" :
 
90
  row.status === "failed" ? "bg-[var(--clay-red)]/10 text-[var(--clay-red)]" :
91
  row.status === "cancelled" ? "bg-[var(--oat-border)] text-[var(--warm-charcoal)]" :
92
  row.status === "running" ? "bg-[var(--sunbeam-300)] text-[var(--sunbeam-800)]" :
 
8
  import { DataTable } from "@/components/admin/DataTable";
9
  import type { ColumnDef } from "@/components/admin/DataTable";
10
 
11
+ const STATUSES = ["all", "pending", "running", "completed", "completed_partial", "failed", "cancelled"] as const;
12
 
13
  export const Route = createFileRoute("/admin/jobs")({
14
  component: AdminJobs,
 
87
  cell: ({ row }) => (
88
  <span className={`text-xs font-semibold px-2 py-0.5 rounded-full ${
89
  row.status === "completed" ? "bg-[var(--matcha-300)] text-[var(--matcha-800)]" :
90
+ row.status === "completed_partial" ? "bg-[var(--pomegranate-400)]/10 text-[var(--pomegranate-400)]" :
91
  row.status === "failed" ? "bg-[var(--clay-red)]/10 text-[var(--clay-red)]" :
92
  row.status === "cancelled" ? "bg-[var(--oat-border)] text-[var(--warm-charcoal)]" :
93
  row.status === "running" ? "bg-[var(--sunbeam-300)] text-[var(--sunbeam-800)]" :
apps/web/src/routes/jobs.tsx CHANGED
@@ -118,6 +118,7 @@ const STATUS_COLORS: Record<string, string> = {
118
  partial_ready: "bg-[var(--lemon-300)] text-[var(--lemon-800)]",
119
  running_quality: "bg-[var(--matcha-300)] text-[var(--matcha-800)]",
120
  completed: "bg-[var(--lemon-300)] text-[var(--lemon-800)]",
 
121
  failed: "bg-[var(--pomegranate-400)]/20 text-[var(--pomegranate-400)]",
122
  cancelled: "bg-[var(--warm-silver)] text-[var(--warm-charcoal)]",
123
  };
@@ -129,6 +130,7 @@ const STATUS_ICONS: Record<string, string> = {
129
  partial_ready: "auto_awesome",
130
  running_quality: "tune",
131
  completed: "check_circle",
 
132
  failed: "error",
133
  cancelled: "block",
134
  };
@@ -330,8 +332,13 @@ function RouteComponent() {
330
  )}
331
  </CardHeader>
332
 
333
- {job.status === "completed" && result && (
334
  <CardContent className="pt-0">
 
 
 
 
 
335
  <div className="flex items-center justify-between mb-3">
336
  <div className="text-sm text-[var(--warm-charcoal)]">
337
  {(() => {
 
118
  partial_ready: "bg-[var(--lemon-300)] text-[var(--lemon-800)]",
119
  running_quality: "bg-[var(--matcha-300)] text-[var(--matcha-800)]",
120
  completed: "bg-[var(--lemon-300)] text-[var(--lemon-800)]",
121
+ completed_partial: "bg-[var(--pomegranate-400)]/20 text-[var(--pomegranate-400)]",
122
  failed: "bg-[var(--pomegranate-400)]/20 text-[var(--pomegranate-400)]",
123
  cancelled: "bg-[var(--warm-silver)] text-[var(--warm-charcoal)]",
124
  };
 
130
  partial_ready: "auto_awesome",
131
  running_quality: "tune",
132
  completed: "check_circle",
133
+ completed_partial: "warning",
134
  failed: "error",
135
  cancelled: "block",
136
  };
 
332
  )}
333
  </CardHeader>
334
 
335
+ {(job.status === "completed" || job.status === "completed_partial") && result && (
336
  <CardContent className="pt-0">
337
+ {job.status === "completed_partial" && job.errorMessage && (
338
+ <div className="mb-3 p-3 rounded-[var(--radius-md)] bg-[var(--pomegranate-400)]/10 border border-[var(--pomegranate-400)]/20 text-sm text-[var(--pomegranate-400)]">
339
+ {job.errorMessage}
340
+ </div>
341
+ )}
342
  <div className="flex items-center justify-between mb-3">
343
  <div className="text-sm text-[var(--warm-charcoal)]">
344
  {(() => {
deploy/COOLIFY.md CHANGED
@@ -155,7 +155,7 @@ Alternative for local-style sync (not recommended in production): `bun run db:pu
155
  Optional seed (run once via **Terminal** on the server app):
156
 
157
  ```bash
158
- cd packages/db && bun run db:seed
159
  ```
160
 
161
  ### Verify
 
155
  Optional seed (run once via **Terminal** on the server app):
156
 
157
  ```bash
158
+ bun run db:seed
159
  ```
160
 
161
  ### Verify
package.json CHANGED
@@ -31,6 +31,7 @@
31
  "db:studio": "turbo -F @labas/db db:studio",
32
  "db:generate": "turbo -F @labas/db db:generate",
33
  "db:migrate": "turbo -F @labas/db db:migrate",
 
34
  "db:start": "turbo -F @labas/db db:start",
35
  "db:watch": "turbo -F @labas/db db:watch",
36
  "db:stop": "turbo -F @labas/db db:stop",
 
31
  "db:studio": "turbo -F @labas/db db:studio",
32
  "db:generate": "turbo -F @labas/db db:generate",
33
  "db:migrate": "turbo -F @labas/db db:migrate",
34
+ "db:seed": "turbo -F @labas/db db:seed",
35
  "db:start": "turbo -F @labas/db db:start",
36
  "db:watch": "turbo -F @labas/db db:watch",
37
  "db:stop": "turbo -F @labas/db db:stop",
packages/api/src/__tests__/generation-outcome.test.ts ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { describe, expect, it } from "bun:test";
2
+ import {
3
+ isNonRetryableProviderError,
4
+ resolveGenerationJobOutcome,
5
+ sectionsWithNoQuestions,
6
+ } from "../lib/generation-outcome";
7
+
8
+ describe("isNonRetryableProviderError", () => {
9
+ it("detects OpenAI-compatible 500 errors", () => {
10
+ expect(
11
+ isNonRetryableProviderError(
12
+ new Error('OpenAI-compatible API error 500: {"error":{"message":"litellm.MidStreamFallbackError"}}'),
13
+ ),
14
+ ).toBe(true);
15
+ });
16
+
17
+ it("detects LiteLLM connection errors", () => {
18
+ expect(isNonRetryableProviderError(new Error("litellm.APIConnectionError: upstream failed"))).toBe(
19
+ true,
20
+ );
21
+ });
22
+
23
+ it("returns false for JSON parse failures", () => {
24
+ expect(isNonRetryableProviderError(new Error("Failed to parse AI response as JSON"))).toBe(false);
25
+ });
26
+ });
27
+
28
+ describe("resolveGenerationJobOutcome", () => {
29
+ it("marks full success as completed", () => {
30
+ expect(
31
+ resolveGenerationJobOutcome({ requestedCount: 20, generatedCount: 20 }),
32
+ ).toEqual({
33
+ status: "completed",
34
+ progressMessage: "Completed",
35
+ errorMessage: null,
36
+ });
37
+ });
38
+
39
+ it("marks partial success as completed_partial", () => {
40
+ const outcome = resolveGenerationJobOutcome({
41
+ requestedCount: 20,
42
+ generatedCount: 4,
43
+ failedSections: ["WRITING"],
44
+ });
45
+ expect(outcome.status).toBe("completed_partial");
46
+ expect(outcome.errorMessage).toContain("4 dari 20");
47
+ expect(outcome.errorMessage).toContain("WRITING");
48
+ });
49
+
50
+ it("marks zero questions as failed", () => {
51
+ const outcome = resolveGenerationJobOutcome({
52
+ requestedCount: 20,
53
+ generatedCount: 0,
54
+ failedSections: ["READING", "WRITING"],
55
+ });
56
+ expect(outcome.status).toBe("failed");
57
+ expect(outcome.errorMessage).toContain("Tidak ada soal");
58
+ });
59
+ });
60
+
61
+ describe("sectionsWithNoQuestions", () => {
62
+ it("returns sections missing from generated questions", () => {
63
+ expect(
64
+ sectionsWithNoQuestions(
65
+ [
66
+ { section: "READING", count: 10 },
67
+ { section: "WRITING", count: 10 },
68
+ ],
69
+ [{ section: "READING" }, { section: "READING" }],
70
+ ),
71
+ ).toEqual(["WRITING"]);
72
+ });
73
+ });
packages/api/src/lib/generation-outcome.ts ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export function isNonRetryableProviderError(error: unknown): boolean {
2
+ const message = error instanceof Error ? error.message : String(error);
3
+ const lower = message.toLowerCase();
4
+
5
+ if (/openai-compatible api error 5\d\d/i.test(message)) return true;
6
+ if (/api error 5\d\d/i.test(message)) return true;
7
+ if (lower.includes("midstreamfallbackerror")) return true;
8
+ if (lower.includes("apiconnectionerror")) return true;
9
+ if (lower.includes("provider returned html")) return true;
10
+ if (/\berror 502\b/.test(lower) || /\berror 503\b/.test(lower) || /\berror 504\b/.test(lower)) {
11
+ return true;
12
+ }
13
+
14
+ return false;
15
+ }
16
+
17
+ export function resolveGenerationJobOutcome(input: {
18
+ requestedCount: number;
19
+ generatedCount: number;
20
+ failedSections?: string[];
21
+ }): {
22
+ status: "completed" | "completed_partial" | "failed";
23
+ progressMessage: string;
24
+ errorMessage: string | null;
25
+ } {
26
+ const failedSections = [...new Set(input.failedSections ?? [])];
27
+ const sectionHint =
28
+ failedSections.length > 0 ? ` Section gagal: ${failedSections.join(", ")}.` : "";
29
+
30
+ if (input.generatedCount <= 0) {
31
+ return {
32
+ status: "failed",
33
+ progressMessage: "Generation failed",
34
+ errorMessage: `Tidak ada soal yang berhasil dibuat.${sectionHint} Periksa model/API provider.`,
35
+ };
36
+ }
37
+
38
+ if (input.generatedCount < input.requestedCount) {
39
+ return {
40
+ status: "completed_partial",
41
+ progressMessage: `Selesai sebagian: ${input.generatedCount}/${input.requestedCount} soal`,
42
+ errorMessage: `Hanya ${input.generatedCount} dari ${input.requestedCount} soal berhasil dibuat.${sectionHint}`,
43
+ };
44
+ }
45
+
46
+ return {
47
+ status: "completed",
48
+ progressMessage: "Completed",
49
+ errorMessage: null,
50
+ };
51
+ }
52
+
53
+ export function sectionsWithNoQuestions(
54
+ sectionSplits: Array<{ section: string; count: number }>,
55
+ questions: Array<{ section: string }>,
56
+ ): string[] {
57
+ return sectionSplits
58
+ .filter((split) => !questions.some((q) => q.section === split.section))
59
+ .map((split) => split.section);
60
+ }
packages/api/src/queue.ts CHANGED
@@ -26,6 +26,11 @@ import {
26
  } from "@labas/db";
27
  import { and, eq, notInArray } from "drizzle-orm";
28
  import { encryptApiKey, decryptApiKey } from "./lib/encryption";
 
 
 
 
 
29
 
30
  const connectionOptions = { maxRetriesPerRequest: null };
31
  const FAST_QUEUE_NAME = "generation-fast";
@@ -359,15 +364,17 @@ async function saveGeneratedArtifacts(
359
  .returning();
360
 
361
  if (sec) {
362
- await db.insert(sectionQuestion).values(
363
- sectionQuestions
364
- .map((q, idx) => ({
365
- sectionId: sec.id,
366
- questionId: savedQuestionIds[q._globalIndex],
367
- orderIndex: idx,
368
- }))
369
- .filter((q) => q.questionId != null) as any,
370
- );
 
 
371
  }
372
  }
373
  } catch (packageErr: any) {
@@ -383,10 +390,36 @@ async function saveGeneratedArtifacts(
383
  return { savedQuestionIds, generatedPackageId };
384
  }
385
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
  async function completeJobWithResult(params: {
387
  jobId: string;
388
  input: GenerationInput;
 
389
  statusMessage?: string;
 
390
  allQuestions: PersistableQuestion[];
391
  sectionSplits: SectionSplit[];
392
  totalTokens: number;
@@ -420,9 +453,10 @@ async function completeJobWithResult(params: {
420
  await db
421
  .update(generationJob)
422
  .set({
423
- status: "completed",
424
  progress: 100,
425
  progressMessage: params.statusMessage ?? "Completed",
 
426
  resultJson: {
427
  ...result,
428
  savedQuestionIds,
@@ -430,6 +464,8 @@ async function completeJobWithResult(params: {
430
  sectionSplits: params.sectionSplits,
431
  qualityPhase: "final",
432
  metrics: params.metrics,
 
 
433
  } as any,
434
  tokensUsed: params.totalTokens,
435
  durationMs: params.durationMs,
@@ -489,7 +525,7 @@ export async function cancelGenerationJob(
489
 
490
  if (!row) return { ok: false, reason: "not_found" };
491
  if (row.userId !== userId) return { ok: false, reason: "forbidden" };
492
- if (row.status === "completed" || row.status === "failed" || row.status === "cancelled") {
493
  return { ok: false, reason: "not_cancellable" };
494
  }
495
 
@@ -535,7 +571,8 @@ export const generationWorker = new Worker<FastJobData>(
535
  if (
536
  !initialRow ||
537
  initialRow.status === "cancelled" ||
538
- initialRow.status === "completed"
 
539
  ) {
540
  return;
541
  }
@@ -546,7 +583,7 @@ export const generationWorker = new Worker<FastJobData>(
546
  .where(
547
  and(
548
  eq(generationJob.id, jobId),
549
- notInArray(generationJob.status, ["cancelled", "completed"]),
550
  ),
551
  )
552
  .returning({ id: generationJob.id });
@@ -827,24 +864,50 @@ export const generationWorker = new Worker<FastJobData>(
827
  };
828
 
829
  const failedShards: ShardPlan[] = [];
 
830
  await runWithConcurrency(shards, FAST_SHARD_CONCURRENCY, async (shard) => {
831
  try {
832
  await runShard(shard);
833
- } catch {
834
- log("warn", "[GENERATION] Fast shard failed.", { jobId, section: shard.section });
 
 
 
 
 
 
 
 
 
835
  failedShards.push(shard);
836
  }
837
  });
838
 
839
  if (failedShards.length > 0) {
840
- await pushLog(
841
- "retry_budget",
842
- `Retrying ${failedShards.length} failed shard(s), budget=${MAX_SHARD_RETRIES}`,
843
- "running",
844
- );
 
 
 
 
 
845
  }
846
 
847
  for (const failedShard of failedShards) {
 
 
 
 
 
 
 
 
 
 
 
848
  let success = false;
849
  for (let attempt = 1; attempt <= MAX_SHARD_RETRIES; attempt++) {
850
  try {
@@ -852,14 +915,24 @@ export const generationWorker = new Worker<FastJobData>(
852
  success = true;
853
  break;
854
  } catch (retryErr: any) {
 
 
 
 
 
 
 
 
 
 
855
  await pushLog(
856
  "retry_budget",
857
- `[${failedShard.section}] shard retry ${attempt}/${MAX_SHARD_RETRIES} failed: ${retryErr?.message ?? String(retryErr)}`,
858
  "error",
859
  );
860
  }
861
  }
862
- if (!success) {
863
  await pushLog(
864
  "retry_budget",
865
  `[${failedShard.section}] exhausted retry budget`,
@@ -878,59 +951,66 @@ export const generationWorker = new Worker<FastJobData>(
878
  .flatMap((r) => r.questions)
879
  .slice(0, input.questionCount);
880
 
881
- if (allQuestions.length === 0) {
882
- throw new Error("No questions generated in fast phase");
883
- }
884
-
885
- const fastResult: GenerationResult = {
886
- questions: allQuestions as any,
887
- meta: {
888
- model: input.apiKeyConfig.model,
889
- tokensUsed: totalTokens || approxTokens,
890
- durationMs: totalDurationMs || Date.now() - start,
891
- mode: input.mode,
892
- },
893
- };
894
 
895
- if (selectedMode === "agentic") {
896
- await pushLog("save", "Saving agentic result...", "running");
897
- await completeJobWithResult({
898
  jobId,
899
- input,
900
- allQuestions,
901
- sectionSplits,
902
- totalTokens: totalTokens || approxTokens,
903
  durationMs: Date.now() - start,
904
- statusMessage: "Completed",
905
- metrics: {
906
- timeToFirstValidQuestionMs: timeToFirstValidQuestionMs ?? Date.now() - start,
907
- shardCount: shards.length,
908
- shardRetryBudget: MAX_SHARD_RETRIES,
909
- shardFailures: failedShards.length,
910
- singlePassAgentic: true,
911
- },
912
  });
913
- await pushLog("save", `Saved ${allQuestions.length} questions`, "done");
914
  return;
915
  }
916
 
917
- await pushLog("save", "Saving quick result...", "running");
918
- await completeJobWithResult({
919
  jobId,
920
  input,
921
  allQuestions,
922
  sectionSplits,
923
  totalTokens: totalTokens || approxTokens,
924
  durationMs: Date.now() - start,
925
- statusMessage: "Completed",
 
 
926
  metrics: {
927
  timeToFirstValidQuestionMs: timeToFirstValidQuestionMs ?? Date.now() - start,
928
  shardCount: shards.length,
929
  shardRetryBudget: MAX_SHARD_RETRIES,
930
  shardFailures: failedShards.length,
 
 
 
931
  },
932
- });
933
- await pushLog("save", `Saved ${allQuestions.length} questions`, "done");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
934
  } catch (err: any) {
935
  if (
936
  err instanceof GenerationJobCancelledError ||
@@ -962,7 +1042,7 @@ export const generationWorker = new Worker<FastJobData>(
962
  completedAt: new Date(),
963
  })
964
  .where(eq(generationJob.id, jobId));
965
- throw err;
966
  } finally {
967
  stopHeartbeat();
968
  cancelPoll.stop();
@@ -989,7 +1069,8 @@ export const generationQualityWorker = new Worker<QualityJobData>(
989
  if (
990
  !initialRow ||
991
  initialRow.status === "cancelled" ||
992
- initialRow.status === "completed"
 
993
  ) {
994
  return;
995
  }
@@ -1178,7 +1259,7 @@ export const generationQualityWorker = new Worker<QualityJobData>(
1178
  completedAt: new Date(),
1179
  })
1180
  .where(eq(generationJob.id, jobId));
1181
- throw err;
1182
  } finally {
1183
  cancelPoll.stop();
1184
  }
@@ -1224,11 +1305,7 @@ export async function enqueueGeneration(
1224
  jobId: jobRecord.id,
1225
  removeOnComplete: { count: 100 },
1226
  removeOnFail: { count: 100 },
1227
- attempts: 3,
1228
- backoff: {
1229
- type: "exponential",
1230
- delay: 5000,
1231
- },
1232
  },
1233
  );
1234
 
 
26
  } from "@labas/db";
27
  import { and, eq, notInArray } from "drizzle-orm";
28
  import { encryptApiKey, decryptApiKey } from "./lib/encryption";
29
+ import {
30
+ isNonRetryableProviderError,
31
+ resolveGenerationJobOutcome,
32
+ sectionsWithNoQuestions,
33
+ } from "./lib/generation-outcome";
34
 
35
  const connectionOptions = { maxRetriesPerRequest: null };
36
  const FAST_QUEUE_NAME = "generation-fast";
 
364
  .returning();
365
 
366
  if (sec) {
367
+ const sectionQuestionRows = sectionQuestions
368
+ .map((q, idx) => ({
369
+ sectionId: sec.id,
370
+ questionId: savedQuestionIds[q._globalIndex],
371
+ orderIndex: idx,
372
+ }))
373
+ .filter((q) => q.questionId != null);
374
+
375
+ if (sectionQuestionRows.length > 0) {
376
+ await db.insert(sectionQuestion).values(sectionQuestionRows as any);
377
+ }
378
  }
379
  }
380
  } catch (packageErr: any) {
 
390
  return { savedQuestionIds, generatedPackageId };
391
  }
392
 
393
+ function shardKey(shard: ShardPlan): string {
394
+ return `${shard.sectionIndex}:${shard.shardIndex}`;
395
+ }
396
+
397
+ async function failGenerationJob(params: {
398
+ jobId: string;
399
+ errorMessage: string;
400
+ tokensUsed?: number;
401
+ durationMs: number;
402
+ }) {
403
+ await db
404
+ .update(generationJob)
405
+ .set({
406
+ status: "failed",
407
+ progress: 100,
408
+ progressMessage: "Generation failed",
409
+ errorMessage: params.errorMessage,
410
+ tokensUsed: params.tokensUsed,
411
+ durationMs: params.durationMs,
412
+ completedAt: new Date(),
413
+ })
414
+ .where(eq(generationJob.id, params.jobId));
415
+ }
416
+
417
  async function completeJobWithResult(params: {
418
  jobId: string;
419
  input: GenerationInput;
420
+ status?: "completed" | "completed_partial";
421
  statusMessage?: string;
422
+ errorMessage?: string | null;
423
  allQuestions: PersistableQuestion[];
424
  sectionSplits: SectionSplit[];
425
  totalTokens: number;
 
453
  await db
454
  .update(generationJob)
455
  .set({
456
+ status: params.status ?? "completed",
457
  progress: 100,
458
  progressMessage: params.statusMessage ?? "Completed",
459
+ errorMessage: params.errorMessage ?? null,
460
  resultJson: {
461
  ...result,
462
  savedQuestionIds,
 
464
  sectionSplits: params.sectionSplits,
465
  qualityPhase: "final",
466
  metrics: params.metrics,
467
+ isPartial: params.status === "completed_partial",
468
+ requestedQuestionCount: params.input.questionCount,
469
  } as any,
470
  tokensUsed: params.totalTokens,
471
  durationMs: params.durationMs,
 
525
 
526
  if (!row) return { ok: false, reason: "not_found" };
527
  if (row.userId !== userId) return { ok: false, reason: "forbidden" };
528
+ if (row.status === "completed" || row.status === "completed_partial" || row.status === "failed" || row.status === "cancelled") {
529
  return { ok: false, reason: "not_cancellable" };
530
  }
531
 
 
571
  if (
572
  !initialRow ||
573
  initialRow.status === "cancelled" ||
574
+ initialRow.status === "completed" ||
575
+ initialRow.status === "completed_partial"
576
  ) {
577
  return;
578
  }
 
583
  .where(
584
  and(
585
  eq(generationJob.id, jobId),
586
+ notInArray(generationJob.status, ["cancelled", "completed", "completed_partial"]),
587
  ),
588
  )
589
  .returning({ id: generationJob.id });
 
864
  };
865
 
866
  const failedShards: ShardPlan[] = [];
867
+ const shardFailureInfo = new Map<string, { error: string; nonRetryable: boolean }>();
868
  await runWithConcurrency(shards, FAST_SHARD_CONCURRENCY, async (shard) => {
869
  try {
870
  await runShard(shard);
871
+ } catch (err: any) {
872
+ const message = err?.message ?? String(err);
873
+ shardFailureInfo.set(shardKey(shard), {
874
+ error: message,
875
+ nonRetryable: isNonRetryableProviderError(err),
876
+ });
877
+ log("warn", "[GENERATION] Fast shard failed.", {
878
+ jobId,
879
+ section: shard.section,
880
+ nonRetryable: isNonRetryableProviderError(err),
881
+ });
882
  failedShards.push(shard);
883
  }
884
  });
885
 
886
  if (failedShards.length > 0) {
887
+ const retryableCount = failedShards.filter(
888
+ (shard) => !shardFailureInfo.get(shardKey(shard))?.nonRetryable,
889
+ ).length;
890
+ if (retryableCount > 0) {
891
+ await pushLog(
892
+ "retry_budget",
893
+ `Retrying ${retryableCount} failed shard(s), budget=${MAX_SHARD_RETRIES}`,
894
+ "running",
895
+ );
896
+ }
897
  }
898
 
899
  for (const failedShard of failedShards) {
900
+ const failure = shardFailureInfo.get(shardKey(failedShard));
901
+ if (failure?.nonRetryable) {
902
+ await pushLog(
903
+ "retry_budget",
904
+ `[${failedShard.section}] provider error — skipping retries`,
905
+ "error",
906
+ failure.error.slice(0, 300),
907
+ );
908
+ continue;
909
+ }
910
+
911
  let success = false;
912
  for (let attempt = 1; attempt <= MAX_SHARD_RETRIES; attempt++) {
913
  try {
 
915
  success = true;
916
  break;
917
  } catch (retryErr: any) {
918
+ const retryMessage = retryErr?.message ?? String(retryErr);
919
+ if (isNonRetryableProviderError(retryErr)) {
920
+ await pushLog(
921
+ "retry_budget",
922
+ `[${failedShard.section}] provider error — stopping retries`,
923
+ "error",
924
+ retryMessage.slice(0, 300),
925
+ );
926
+ break;
927
+ }
928
  await pushLog(
929
  "retry_budget",
930
+ `[${failedShard.section}] shard retry ${attempt}/${MAX_SHARD_RETRIES} failed: ${retryMessage}`,
931
  "error",
932
  );
933
  }
934
  }
935
+ if (!success && !failure?.nonRetryable) {
936
  await pushLog(
937
  "retry_budget",
938
  `[${failedShard.section}] exhausted retry budget`,
 
951
  .flatMap((r) => r.questions)
952
  .slice(0, input.questionCount);
953
 
954
+ const outcome = resolveGenerationJobOutcome({
955
+ requestedCount: input.questionCount,
956
+ generatedCount: allQuestions.length,
957
+ failedSections: sectionsWithNoQuestions(sectionSplits, allQuestions),
958
+ });
 
 
 
 
 
 
 
 
959
 
960
+ if (outcome.status === "failed") {
961
+ await pushLog("save", outcome.errorMessage ?? "Generation failed", "error");
962
+ await failGenerationJob({
963
  jobId,
964
+ errorMessage: outcome.errorMessage ?? "Generation failed",
965
+ tokensUsed: totalTokens || approxTokens || undefined,
 
 
966
  durationMs: Date.now() - start,
 
 
 
 
 
 
 
 
967
  });
 
968
  return;
969
  }
970
 
971
+ const finalizeParams = {
 
972
  jobId,
973
  input,
974
  allQuestions,
975
  sectionSplits,
976
  totalTokens: totalTokens || approxTokens,
977
  durationMs: Date.now() - start,
978
+ status: outcome.status,
979
+ statusMessage: outcome.progressMessage,
980
+ errorMessage: outcome.errorMessage,
981
  metrics: {
982
  timeToFirstValidQuestionMs: timeToFirstValidQuestionMs ?? Date.now() - start,
983
  shardCount: shards.length,
984
  shardRetryBudget: MAX_SHARD_RETRIES,
985
  shardFailures: failedShards.length,
986
+ requestedQuestionCount: input.questionCount,
987
+ generatedQuestionCount: allQuestions.length,
988
+ ...(selectedMode === "agentic" ? { singlePassAgentic: true } : {}),
989
  },
990
+ };
991
+
992
+ if (selectedMode === "agentic") {
993
+ await pushLog("save", "Saving agentic result...", "running");
994
+ await completeJobWithResult(finalizeParams);
995
+ await pushLog(
996
+ "save",
997
+ outcome.status === "completed_partial"
998
+ ? `Saved ${allQuestions.length}/${input.questionCount} questions (partial)`
999
+ : `Saved ${allQuestions.length} questions`,
1000
+ outcome.status === "completed_partial" ? "error" : "done",
1001
+ );
1002
+ return;
1003
+ }
1004
+
1005
+ await pushLog("save", "Saving quick result...", "running");
1006
+ await completeJobWithResult(finalizeParams);
1007
+ await pushLog(
1008
+ "save",
1009
+ outcome.status === "completed_partial"
1010
+ ? `Saved ${allQuestions.length}/${input.questionCount} questions (partial)`
1011
+ : `Saved ${allQuestions.length} questions`,
1012
+ outcome.status === "completed_partial" ? "error" : "done",
1013
+ );
1014
  } catch (err: any) {
1015
  if (
1016
  err instanceof GenerationJobCancelledError ||
 
1042
  completedAt: new Date(),
1043
  })
1044
  .where(eq(generationJob.id, jobId));
1045
+ return;
1046
  } finally {
1047
  stopHeartbeat();
1048
  cancelPoll.stop();
 
1069
  if (
1070
  !initialRow ||
1071
  initialRow.status === "cancelled" ||
1072
+ initialRow.status === "completed" ||
1073
+ initialRow.status === "completed_partial"
1074
  ) {
1075
  return;
1076
  }
 
1259
  completedAt: new Date(),
1260
  })
1261
  .where(eq(generationJob.id, jobId));
1262
+ return;
1263
  } finally {
1264
  cancelPoll.stop();
1265
  }
 
1305
  jobId: jobRecord.id,
1306
  removeOnComplete: { count: 100 },
1307
  removeOnFail: { count: 100 },
1308
+ attempts: 1,
 
 
 
 
1309
  },
1310
  );
1311
 
packages/db/drizzle.config.ts CHANGED
@@ -1,28 +1,12 @@
1
- import { existsSync } from "node:fs";
2
- import { dirname, resolve } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import dotenv from "dotenv";
5
  import { defineConfig } from "drizzle-kit";
6
 
7
- const serverEnvPath = resolve(dirname(fileURLToPath(import.meta.url)), "../../apps/server/.env");
8
-
9
- // Coolify/production inject DATABASE_URL via process.env; .env file is local-dev only.
10
- if (!process.env.DATABASE_URL && existsSync(serverEnvPath)) {
11
- dotenv.config({ path: serverEnvPath });
12
- }
13
-
14
- const databaseUrl = process.env.DATABASE_URL;
15
- if (!databaseUrl) {
16
- throw new Error(
17
- "DATABASE_URL is not set. Add it to Coolify environment variables (or apps/server/.env for local dev).",
18
- );
19
- }
20
 
21
  export default defineConfig({
22
  schema: "./src/schema",
23
  out: "./src/migrations",
24
  dialect: "postgresql",
25
  dbCredentials: {
26
- url: databaseUrl,
27
  },
28
  });
 
 
 
 
 
1
  import { defineConfig } from "drizzle-kit";
2
 
3
+ import { loadDatabaseUrl } from "./src/database-url";
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  export default defineConfig({
6
  schema: "./src/schema",
7
  out: "./src/migrations",
8
  dialect: "postgresql",
9
  dbCredentials: {
10
+ url: loadDatabaseUrl(),
11
  },
12
  });
packages/db/src/database-url.ts ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { existsSync } from "node:fs";
2
+ import { dirname, resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import dotenv from "dotenv";
5
+
6
+ const serverEnvPath = resolve(dirname(fileURLToPath(import.meta.url)), "../../../apps/server/.env");
7
+
8
+ export function loadDatabaseUrl(): string {
9
+ if (!process.env.DATABASE_URL && existsSync(serverEnvPath)) {
10
+ dotenv.config({ path: serverEnvPath });
11
+ }
12
+
13
+ const databaseUrl = process.env.DATABASE_URL;
14
+ if (!databaseUrl) {
15
+ throw new Error(
16
+ "DATABASE_URL is not set. Add it to Coolify environment variables (or apps/server/.env for local dev).",
17
+ );
18
+ }
19
+
20
+ return databaseUrl;
21
+ }
packages/db/src/migrations/0004_left_diamondback.sql ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CREATE TABLE IF NOT EXISTS "admin_audit_log" (
2
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
+ "admin_user_id" text NOT NULL,
4
+ "action" text NOT NULL,
5
+ "target_user_id" text,
6
+ "details" jsonb,
7
+ "created_at" timestamp DEFAULT now() NOT NULL
8
+ );
9
+ --> statement-breakpoint
10
+ CREATE TABLE IF NOT EXISTS "credit_transaction" (
11
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
12
+ "user_id" text NOT NULL,
13
+ "amount" integer NOT NULL,
14
+ "type" text NOT NULL,
15
+ "description" text,
16
+ "tokens_used" integer,
17
+ "created_at" timestamp DEFAULT now() NOT NULL
18
+ );
19
+ --> statement-breakpoint
20
+ CREATE TABLE IF NOT EXISTS "platform_config" (
21
+ "key" text PRIMARY KEY NOT NULL,
22
+ "value" text NOT NULL,
23
+ "updated_at" timestamp DEFAULT now() NOT NULL
24
+ );
25
+ --> statement-breakpoint
26
+ CREATE TABLE IF NOT EXISTS "user_credit" (
27
+ "user_id" text PRIMARY KEY NOT NULL,
28
+ "token_balance" integer DEFAULT 0 NOT NULL,
29
+ "lifetime_tokens_used" integer DEFAULT 0 NOT NULL,
30
+ "created_at" timestamp DEFAULT now() NOT NULL,
31
+ "updated_at" timestamp DEFAULT now() NOT NULL
32
+ );
33
+ --> statement-breakpoint
34
+ ALTER TABLE "answer" ADD COLUMN IF NOT EXISTS "partial_score" integer;--> statement-breakpoint
35
+ ALTER TABLE "generation_job" ADD COLUMN IF NOT EXISTS "input_json" jsonb;--> statement-breakpoint
36
+ ALTER TABLE "question" ADD COLUMN IF NOT EXISTS "is_case_sensitive" boolean DEFAULT false NOT NULL;--> statement-breakpoint
37
+ ALTER TABLE "question" ADD COLUMN IF NOT EXISTS "is_featured" boolean DEFAULT false NOT NULL;--> statement-breakpoint
38
+ ALTER TABLE "user" ADD COLUMN IF NOT EXISTS "role" text DEFAULT 'user' NOT NULL;--> statement-breakpoint
39
+ ALTER TABLE "user" ADD COLUMN IF NOT EXISTS "suspended" boolean DEFAULT false NOT NULL;--> statement-breakpoint
40
+ DO $$ BEGIN
41
+ ALTER TABLE "admin_audit_log" ADD CONSTRAINT "admin_audit_log_admin_user_id_user_id_fk" FOREIGN KEY ("admin_user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
42
+ EXCEPTION
43
+ WHEN duplicate_object THEN null;
44
+ END $$;
45
+ --> statement-breakpoint
46
+ DO $$ BEGIN
47
+ ALTER TABLE "admin_audit_log" ADD CONSTRAINT "admin_audit_log_target_user_id_user_id_fk" FOREIGN KEY ("target_user_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;
48
+ EXCEPTION
49
+ WHEN duplicate_object THEN null;
50
+ END $$;
51
+ --> statement-breakpoint
52
+ DO $$ BEGIN
53
+ ALTER TABLE "credit_transaction" ADD CONSTRAINT "credit_transaction_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
54
+ EXCEPTION
55
+ WHEN duplicate_object THEN null;
56
+ END $$;
57
+ --> statement-breakpoint
58
+ DO $$ BEGIN
59
+ ALTER TABLE "user_credit" ADD CONSTRAINT "user_credit_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
60
+ EXCEPTION
61
+ WHEN duplicate_object THEN null;
62
+ END $$;
63
+ --> statement-breakpoint
64
+ CREATE INDEX IF NOT EXISTS "adminAuditLog_adminUserId_idx" ON "admin_audit_log" USING btree ("admin_user_id");--> statement-breakpoint
65
+ CREATE INDEX IF NOT EXISTS "adminAuditLog_action_idx" ON "admin_audit_log" USING btree ("action");--> statement-breakpoint
66
+ CREATE INDEX IF NOT EXISTS "creditTransaction_userId_idx" ON "credit_transaction" USING btree ("user_id");--> statement-breakpoint
67
+ CREATE INDEX IF NOT EXISTS "userCredit_userId_idx" ON "user_credit" USING btree ("user_id");
packages/db/src/migrations/meta/0004_snapshot.json ADDED
@@ -0,0 +1,2487 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "ac52ab5d-b06e-4cd4-8c2a-c38ad8fe4637",
3
+ "prevId": "f3629c12-2ab8-49c1-b6e5-8b5365ce47dc",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "public.admin_audit_log": {
8
+ "name": "admin_audit_log",
9
+ "schema": "",
10
+ "columns": {
11
+ "id": {
12
+ "name": "id",
13
+ "type": "uuid",
14
+ "primaryKey": true,
15
+ "notNull": true,
16
+ "default": "gen_random_uuid()"
17
+ },
18
+ "admin_user_id": {
19
+ "name": "admin_user_id",
20
+ "type": "text",
21
+ "primaryKey": false,
22
+ "notNull": true
23
+ },
24
+ "action": {
25
+ "name": "action",
26
+ "type": "text",
27
+ "primaryKey": false,
28
+ "notNull": true
29
+ },
30
+ "target_user_id": {
31
+ "name": "target_user_id",
32
+ "type": "text",
33
+ "primaryKey": false,
34
+ "notNull": false
35
+ },
36
+ "details": {
37
+ "name": "details",
38
+ "type": "jsonb",
39
+ "primaryKey": false,
40
+ "notNull": false
41
+ },
42
+ "created_at": {
43
+ "name": "created_at",
44
+ "type": "timestamp",
45
+ "primaryKey": false,
46
+ "notNull": true,
47
+ "default": "now()"
48
+ }
49
+ },
50
+ "indexes": {
51
+ "adminAuditLog_adminUserId_idx": {
52
+ "name": "adminAuditLog_adminUserId_idx",
53
+ "columns": [
54
+ {
55
+ "expression": "admin_user_id",
56
+ "isExpression": false,
57
+ "asc": true,
58
+ "nulls": "last"
59
+ }
60
+ ],
61
+ "isUnique": false,
62
+ "concurrently": false,
63
+ "method": "btree",
64
+ "with": {}
65
+ },
66
+ "adminAuditLog_action_idx": {
67
+ "name": "adminAuditLog_action_idx",
68
+ "columns": [
69
+ {
70
+ "expression": "action",
71
+ "isExpression": false,
72
+ "asc": true,
73
+ "nulls": "last"
74
+ }
75
+ ],
76
+ "isUnique": false,
77
+ "concurrently": false,
78
+ "method": "btree",
79
+ "with": {}
80
+ }
81
+ },
82
+ "foreignKeys": {
83
+ "admin_audit_log_admin_user_id_user_id_fk": {
84
+ "name": "admin_audit_log_admin_user_id_user_id_fk",
85
+ "tableFrom": "admin_audit_log",
86
+ "tableTo": "user",
87
+ "columnsFrom": [
88
+ "admin_user_id"
89
+ ],
90
+ "columnsTo": [
91
+ "id"
92
+ ],
93
+ "onDelete": "cascade",
94
+ "onUpdate": "no action"
95
+ },
96
+ "admin_audit_log_target_user_id_user_id_fk": {
97
+ "name": "admin_audit_log_target_user_id_user_id_fk",
98
+ "tableFrom": "admin_audit_log",
99
+ "tableTo": "user",
100
+ "columnsFrom": [
101
+ "target_user_id"
102
+ ],
103
+ "columnsTo": [
104
+ "id"
105
+ ],
106
+ "onDelete": "set null",
107
+ "onUpdate": "no action"
108
+ }
109
+ },
110
+ "compositePrimaryKeys": {},
111
+ "uniqueConstraints": {},
112
+ "policies": {},
113
+ "checkConstraints": {},
114
+ "isRLSEnabled": false
115
+ },
116
+ "public.credit_transaction": {
117
+ "name": "credit_transaction",
118
+ "schema": "",
119
+ "columns": {
120
+ "id": {
121
+ "name": "id",
122
+ "type": "uuid",
123
+ "primaryKey": true,
124
+ "notNull": true,
125
+ "default": "gen_random_uuid()"
126
+ },
127
+ "user_id": {
128
+ "name": "user_id",
129
+ "type": "text",
130
+ "primaryKey": false,
131
+ "notNull": true
132
+ },
133
+ "amount": {
134
+ "name": "amount",
135
+ "type": "integer",
136
+ "primaryKey": false,
137
+ "notNull": true
138
+ },
139
+ "type": {
140
+ "name": "type",
141
+ "type": "text",
142
+ "primaryKey": false,
143
+ "notNull": true
144
+ },
145
+ "description": {
146
+ "name": "description",
147
+ "type": "text",
148
+ "primaryKey": false,
149
+ "notNull": false
150
+ },
151
+ "tokens_used": {
152
+ "name": "tokens_used",
153
+ "type": "integer",
154
+ "primaryKey": false,
155
+ "notNull": false
156
+ },
157
+ "created_at": {
158
+ "name": "created_at",
159
+ "type": "timestamp",
160
+ "primaryKey": false,
161
+ "notNull": true,
162
+ "default": "now()"
163
+ }
164
+ },
165
+ "indexes": {
166
+ "creditTransaction_userId_idx": {
167
+ "name": "creditTransaction_userId_idx",
168
+ "columns": [
169
+ {
170
+ "expression": "user_id",
171
+ "isExpression": false,
172
+ "asc": true,
173
+ "nulls": "last"
174
+ }
175
+ ],
176
+ "isUnique": false,
177
+ "concurrently": false,
178
+ "method": "btree",
179
+ "with": {}
180
+ }
181
+ },
182
+ "foreignKeys": {
183
+ "credit_transaction_user_id_user_id_fk": {
184
+ "name": "credit_transaction_user_id_user_id_fk",
185
+ "tableFrom": "credit_transaction",
186
+ "tableTo": "user",
187
+ "columnsFrom": [
188
+ "user_id"
189
+ ],
190
+ "columnsTo": [
191
+ "id"
192
+ ],
193
+ "onDelete": "cascade",
194
+ "onUpdate": "no action"
195
+ }
196
+ },
197
+ "compositePrimaryKeys": {},
198
+ "uniqueConstraints": {},
199
+ "policies": {},
200
+ "checkConstraints": {},
201
+ "isRLSEnabled": false
202
+ },
203
+ "public.platform_config": {
204
+ "name": "platform_config",
205
+ "schema": "",
206
+ "columns": {
207
+ "key": {
208
+ "name": "key",
209
+ "type": "text",
210
+ "primaryKey": true,
211
+ "notNull": true
212
+ },
213
+ "value": {
214
+ "name": "value",
215
+ "type": "text",
216
+ "primaryKey": false,
217
+ "notNull": true
218
+ },
219
+ "updated_at": {
220
+ "name": "updated_at",
221
+ "type": "timestamp",
222
+ "primaryKey": false,
223
+ "notNull": true,
224
+ "default": "now()"
225
+ }
226
+ },
227
+ "indexes": {},
228
+ "foreignKeys": {},
229
+ "compositePrimaryKeys": {},
230
+ "uniqueConstraints": {},
231
+ "policies": {},
232
+ "checkConstraints": {},
233
+ "isRLSEnabled": false
234
+ },
235
+ "public.user_credit": {
236
+ "name": "user_credit",
237
+ "schema": "",
238
+ "columns": {
239
+ "user_id": {
240
+ "name": "user_id",
241
+ "type": "text",
242
+ "primaryKey": true,
243
+ "notNull": true
244
+ },
245
+ "token_balance": {
246
+ "name": "token_balance",
247
+ "type": "integer",
248
+ "primaryKey": false,
249
+ "notNull": true,
250
+ "default": 0
251
+ },
252
+ "lifetime_tokens_used": {
253
+ "name": "lifetime_tokens_used",
254
+ "type": "integer",
255
+ "primaryKey": false,
256
+ "notNull": true,
257
+ "default": 0
258
+ },
259
+ "created_at": {
260
+ "name": "created_at",
261
+ "type": "timestamp",
262
+ "primaryKey": false,
263
+ "notNull": true,
264
+ "default": "now()"
265
+ },
266
+ "updated_at": {
267
+ "name": "updated_at",
268
+ "type": "timestamp",
269
+ "primaryKey": false,
270
+ "notNull": true,
271
+ "default": "now()"
272
+ }
273
+ },
274
+ "indexes": {
275
+ "userCredit_userId_idx": {
276
+ "name": "userCredit_userId_idx",
277
+ "columns": [
278
+ {
279
+ "expression": "user_id",
280
+ "isExpression": false,
281
+ "asc": true,
282
+ "nulls": "last"
283
+ }
284
+ ],
285
+ "isUnique": false,
286
+ "concurrently": false,
287
+ "method": "btree",
288
+ "with": {}
289
+ }
290
+ },
291
+ "foreignKeys": {
292
+ "user_credit_user_id_user_id_fk": {
293
+ "name": "user_credit_user_id_user_id_fk",
294
+ "tableFrom": "user_credit",
295
+ "tableTo": "user",
296
+ "columnsFrom": [
297
+ "user_id"
298
+ ],
299
+ "columnsTo": [
300
+ "id"
301
+ ],
302
+ "onDelete": "cascade",
303
+ "onUpdate": "no action"
304
+ }
305
+ },
306
+ "compositePrimaryKeys": {},
307
+ "uniqueConstraints": {},
308
+ "policies": {},
309
+ "checkConstraints": {},
310
+ "isRLSEnabled": false
311
+ },
312
+ "public.answer": {
313
+ "name": "answer",
314
+ "schema": "",
315
+ "columns": {
316
+ "id": {
317
+ "name": "id",
318
+ "type": "uuid",
319
+ "primaryKey": true,
320
+ "notNull": true,
321
+ "default": "gen_random_uuid()"
322
+ },
323
+ "section_result_id": {
324
+ "name": "section_result_id",
325
+ "type": "uuid",
326
+ "primaryKey": false,
327
+ "notNull": true
328
+ },
329
+ "question_id": {
330
+ "name": "question_id",
331
+ "type": "uuid",
332
+ "primaryKey": false,
333
+ "notNull": true
334
+ },
335
+ "user_answer": {
336
+ "name": "user_answer",
337
+ "type": "text",
338
+ "primaryKey": false,
339
+ "notNull": false
340
+ },
341
+ "is_correct": {
342
+ "name": "is_correct",
343
+ "type": "boolean",
344
+ "primaryKey": false,
345
+ "notNull": false
346
+ },
347
+ "partial_score": {
348
+ "name": "partial_score",
349
+ "type": "integer",
350
+ "primaryKey": false,
351
+ "notNull": false
352
+ },
353
+ "time_spent_sec": {
354
+ "name": "time_spent_sec",
355
+ "type": "integer",
356
+ "primaryKey": false,
357
+ "notNull": false
358
+ },
359
+ "created_at": {
360
+ "name": "created_at",
361
+ "type": "timestamp",
362
+ "primaryKey": false,
363
+ "notNull": true,
364
+ "default": "now()"
365
+ }
366
+ },
367
+ "indexes": {
368
+ "answer_questionId_idx": {
369
+ "name": "answer_questionId_idx",
370
+ "columns": [
371
+ {
372
+ "expression": "question_id",
373
+ "isExpression": false,
374
+ "asc": true,
375
+ "nulls": "last"
376
+ }
377
+ ],
378
+ "isUnique": false,
379
+ "concurrently": false,
380
+ "method": "btree",
381
+ "with": {}
382
+ }
383
+ },
384
+ "foreignKeys": {
385
+ "answer_section_result_id_section_result_id_fk": {
386
+ "name": "answer_section_result_id_section_result_id_fk",
387
+ "tableFrom": "answer",
388
+ "tableTo": "section_result",
389
+ "columnsFrom": [
390
+ "section_result_id"
391
+ ],
392
+ "columnsTo": [
393
+ "id"
394
+ ],
395
+ "onDelete": "cascade",
396
+ "onUpdate": "no action"
397
+ },
398
+ "answer_question_id_question_id_fk": {
399
+ "name": "answer_question_id_question_id_fk",
400
+ "tableFrom": "answer",
401
+ "tableTo": "question",
402
+ "columnsFrom": [
403
+ "question_id"
404
+ ],
405
+ "columnsTo": [
406
+ "id"
407
+ ],
408
+ "onDelete": "cascade",
409
+ "onUpdate": "no action"
410
+ }
411
+ },
412
+ "compositePrimaryKeys": {},
413
+ "uniqueConstraints": {
414
+ "answer_unique_idx": {
415
+ "name": "answer_unique_idx",
416
+ "nullsNotDistinct": false,
417
+ "columns": [
418
+ "section_result_id",
419
+ "question_id"
420
+ ]
421
+ }
422
+ },
423
+ "policies": {},
424
+ "checkConstraints": {},
425
+ "isRLSEnabled": false
426
+ },
427
+ "public.combo_package": {
428
+ "name": "combo_package",
429
+ "schema": "",
430
+ "columns": {
431
+ "id": {
432
+ "name": "id",
433
+ "type": "uuid",
434
+ "primaryKey": true,
435
+ "notNull": true,
436
+ "default": "gen_random_uuid()"
437
+ },
438
+ "title": {
439
+ "name": "title",
440
+ "type": "text",
441
+ "primaryKey": false,
442
+ "notNull": true
443
+ },
444
+ "description": {
445
+ "name": "description",
446
+ "type": "text",
447
+ "primaryKey": false,
448
+ "notNull": false
449
+ },
450
+ "creator_user_id": {
451
+ "name": "creator_user_id",
452
+ "type": "text",
453
+ "primaryKey": false,
454
+ "notNull": true
455
+ },
456
+ "is_public": {
457
+ "name": "is_public",
458
+ "type": "boolean",
459
+ "primaryKey": false,
460
+ "notNull": true,
461
+ "default": false
462
+ },
463
+ "created_at": {
464
+ "name": "created_at",
465
+ "type": "timestamp",
466
+ "primaryKey": false,
467
+ "notNull": true,
468
+ "default": "now()"
469
+ },
470
+ "updated_at": {
471
+ "name": "updated_at",
472
+ "type": "timestamp",
473
+ "primaryKey": false,
474
+ "notNull": true,
475
+ "default": "now()"
476
+ }
477
+ },
478
+ "indexes": {
479
+ "comboPackage_creatorUserId_idx": {
480
+ "name": "comboPackage_creatorUserId_idx",
481
+ "columns": [
482
+ {
483
+ "expression": "creator_user_id",
484
+ "isExpression": false,
485
+ "asc": true,
486
+ "nulls": "last"
487
+ }
488
+ ],
489
+ "isUnique": false,
490
+ "concurrently": false,
491
+ "method": "btree",
492
+ "with": {}
493
+ },
494
+ "comboPackage_isPublic_idx": {
495
+ "name": "comboPackage_isPublic_idx",
496
+ "columns": [
497
+ {
498
+ "expression": "is_public",
499
+ "isExpression": false,
500
+ "asc": true,
501
+ "nulls": "last"
502
+ }
503
+ ],
504
+ "isUnique": false,
505
+ "concurrently": false,
506
+ "method": "btree",
507
+ "with": {}
508
+ }
509
+ },
510
+ "foreignKeys": {
511
+ "combo_package_creator_user_id_user_id_fk": {
512
+ "name": "combo_package_creator_user_id_user_id_fk",
513
+ "tableFrom": "combo_package",
514
+ "tableTo": "user",
515
+ "columnsFrom": [
516
+ "creator_user_id"
517
+ ],
518
+ "columnsTo": [
519
+ "id"
520
+ ],
521
+ "onDelete": "cascade",
522
+ "onUpdate": "no action"
523
+ }
524
+ },
525
+ "compositePrimaryKeys": {},
526
+ "uniqueConstraints": {},
527
+ "policies": {},
528
+ "checkConstraints": {},
529
+ "isRLSEnabled": false
530
+ },
531
+ "public.combo_section": {
532
+ "name": "combo_section",
533
+ "schema": "",
534
+ "columns": {
535
+ "id": {
536
+ "name": "id",
537
+ "type": "uuid",
538
+ "primaryKey": true,
539
+ "notNull": true,
540
+ "default": "gen_random_uuid()"
541
+ },
542
+ "combo_id": {
543
+ "name": "combo_id",
544
+ "type": "uuid",
545
+ "primaryKey": false,
546
+ "notNull": true
547
+ },
548
+ "source_package_id": {
549
+ "name": "source_package_id",
550
+ "type": "uuid",
551
+ "primaryKey": false,
552
+ "notNull": true
553
+ },
554
+ "source_section_id": {
555
+ "name": "source_section_id",
556
+ "type": "uuid",
557
+ "primaryKey": false,
558
+ "notNull": true
559
+ },
560
+ "order_index": {
561
+ "name": "order_index",
562
+ "type": "integer",
563
+ "primaryKey": false,
564
+ "notNull": true,
565
+ "default": 0
566
+ }
567
+ },
568
+ "indexes": {
569
+ "comboSection_comboId_idx": {
570
+ "name": "comboSection_comboId_idx",
571
+ "columns": [
572
+ {
573
+ "expression": "combo_id",
574
+ "isExpression": false,
575
+ "asc": true,
576
+ "nulls": "last"
577
+ }
578
+ ],
579
+ "isUnique": false,
580
+ "concurrently": false,
581
+ "method": "btree",
582
+ "with": {}
583
+ },
584
+ "comboSection_sourcePackageId_idx": {
585
+ "name": "comboSection_sourcePackageId_idx",
586
+ "columns": [
587
+ {
588
+ "expression": "source_package_id",
589
+ "isExpression": false,
590
+ "asc": true,
591
+ "nulls": "last"
592
+ }
593
+ ],
594
+ "isUnique": false,
595
+ "concurrently": false,
596
+ "method": "btree",
597
+ "with": {}
598
+ }
599
+ },
600
+ "foreignKeys": {
601
+ "combo_section_combo_id_combo_package_id_fk": {
602
+ "name": "combo_section_combo_id_combo_package_id_fk",
603
+ "tableFrom": "combo_section",
604
+ "tableTo": "combo_package",
605
+ "columnsFrom": [
606
+ "combo_id"
607
+ ],
608
+ "columnsTo": [
609
+ "id"
610
+ ],
611
+ "onDelete": "cascade",
612
+ "onUpdate": "no action"
613
+ },
614
+ "combo_section_source_package_id_test_package_id_fk": {
615
+ "name": "combo_section_source_package_id_test_package_id_fk",
616
+ "tableFrom": "combo_section",
617
+ "tableTo": "test_package",
618
+ "columnsFrom": [
619
+ "source_package_id"
620
+ ],
621
+ "columnsTo": [
622
+ "id"
623
+ ],
624
+ "onDelete": "cascade",
625
+ "onUpdate": "no action"
626
+ },
627
+ "combo_section_source_section_id_package_section_id_fk": {
628
+ "name": "combo_section_source_section_id_package_section_id_fk",
629
+ "tableFrom": "combo_section",
630
+ "tableTo": "package_section",
631
+ "columnsFrom": [
632
+ "source_section_id"
633
+ ],
634
+ "columnsTo": [
635
+ "id"
636
+ ],
637
+ "onDelete": "cascade",
638
+ "onUpdate": "no action"
639
+ }
640
+ },
641
+ "compositePrimaryKeys": {},
642
+ "uniqueConstraints": {},
643
+ "policies": {},
644
+ "checkConstraints": {},
645
+ "isRLSEnabled": false
646
+ },
647
+ "public.exam_type": {
648
+ "name": "exam_type",
649
+ "schema": "",
650
+ "columns": {
651
+ "id": {
652
+ "name": "id",
653
+ "type": "text",
654
+ "primaryKey": true,
655
+ "notNull": true
656
+ },
657
+ "name": {
658
+ "name": "name",
659
+ "type": "text",
660
+ "primaryKey": false,
661
+ "notNull": true
662
+ },
663
+ "language": {
664
+ "name": "language",
665
+ "type": "text",
666
+ "primaryKey": false,
667
+ "notNull": true
668
+ },
669
+ "description": {
670
+ "name": "description",
671
+ "type": "text",
672
+ "primaryKey": false,
673
+ "notNull": false
674
+ }
675
+ },
676
+ "indexes": {},
677
+ "foreignKeys": {},
678
+ "compositePrimaryKeys": {},
679
+ "uniqueConstraints": {},
680
+ "policies": {},
681
+ "checkConstraints": {},
682
+ "isRLSEnabled": false
683
+ },
684
+ "public.generation_job": {
685
+ "name": "generation_job",
686
+ "schema": "",
687
+ "columns": {
688
+ "id": {
689
+ "name": "id",
690
+ "type": "uuid",
691
+ "primaryKey": true,
692
+ "notNull": true,
693
+ "default": "gen_random_uuid()"
694
+ },
695
+ "user_id": {
696
+ "name": "user_id",
697
+ "type": "text",
698
+ "primaryKey": false,
699
+ "notNull": true
700
+ },
701
+ "status": {
702
+ "name": "status",
703
+ "type": "text",
704
+ "primaryKey": false,
705
+ "notNull": true,
706
+ "default": "'pending'"
707
+ },
708
+ "mode": {
709
+ "name": "mode",
710
+ "type": "text",
711
+ "primaryKey": false,
712
+ "notNull": true,
713
+ "default": "'quick'"
714
+ },
715
+ "exam_type_id": {
716
+ "name": "exam_type_id",
717
+ "type": "text",
718
+ "primaryKey": false,
719
+ "notNull": true
720
+ },
721
+ "section_type_id": {
722
+ "name": "section_type_id",
723
+ "type": "text",
724
+ "primaryKey": false,
725
+ "notNull": true
726
+ },
727
+ "question_count": {
728
+ "name": "question_count",
729
+ "type": "integer",
730
+ "primaryKey": false,
731
+ "notNull": true
732
+ },
733
+ "progress": {
734
+ "name": "progress",
735
+ "type": "integer",
736
+ "primaryKey": false,
737
+ "notNull": true,
738
+ "default": 0
739
+ },
740
+ "progress_message": {
741
+ "name": "progress_message",
742
+ "type": "text",
743
+ "primaryKey": false,
744
+ "notNull": false
745
+ },
746
+ "logs": {
747
+ "name": "logs",
748
+ "type": "jsonb",
749
+ "primaryKey": false,
750
+ "notNull": false
751
+ },
752
+ "result_json": {
753
+ "name": "result_json",
754
+ "type": "jsonb",
755
+ "primaryKey": false,
756
+ "notNull": false
757
+ },
758
+ "input_json": {
759
+ "name": "input_json",
760
+ "type": "jsonb",
761
+ "primaryKey": false,
762
+ "notNull": false
763
+ },
764
+ "error_message": {
765
+ "name": "error_message",
766
+ "type": "text",
767
+ "primaryKey": false,
768
+ "notNull": false
769
+ },
770
+ "tokens_used": {
771
+ "name": "tokens_used",
772
+ "type": "integer",
773
+ "primaryKey": false,
774
+ "notNull": false
775
+ },
776
+ "duration_ms": {
777
+ "name": "duration_ms",
778
+ "type": "integer",
779
+ "primaryKey": false,
780
+ "notNull": false
781
+ },
782
+ "created_at": {
783
+ "name": "created_at",
784
+ "type": "timestamp",
785
+ "primaryKey": false,
786
+ "notNull": true,
787
+ "default": "now()"
788
+ },
789
+ "updated_at": {
790
+ "name": "updated_at",
791
+ "type": "timestamp",
792
+ "primaryKey": false,
793
+ "notNull": true,
794
+ "default": "now()"
795
+ },
796
+ "completed_at": {
797
+ "name": "completed_at",
798
+ "type": "timestamp",
799
+ "primaryKey": false,
800
+ "notNull": false
801
+ }
802
+ },
803
+ "indexes": {
804
+ "generationJob_userId_idx": {
805
+ "name": "generationJob_userId_idx",
806
+ "columns": [
807
+ {
808
+ "expression": "user_id",
809
+ "isExpression": false,
810
+ "asc": true,
811
+ "nulls": "last"
812
+ }
813
+ ],
814
+ "isUnique": false,
815
+ "concurrently": false,
816
+ "method": "btree",
817
+ "with": {}
818
+ },
819
+ "generationJob_status_idx": {
820
+ "name": "generationJob_status_idx",
821
+ "columns": [
822
+ {
823
+ "expression": "status",
824
+ "isExpression": false,
825
+ "asc": true,
826
+ "nulls": "last"
827
+ }
828
+ ],
829
+ "isUnique": false,
830
+ "concurrently": false,
831
+ "method": "btree",
832
+ "with": {}
833
+ }
834
+ },
835
+ "foreignKeys": {
836
+ "generation_job_user_id_user_id_fk": {
837
+ "name": "generation_job_user_id_user_id_fk",
838
+ "tableFrom": "generation_job",
839
+ "tableTo": "user",
840
+ "columnsFrom": [
841
+ "user_id"
842
+ ],
843
+ "columnsTo": [
844
+ "id"
845
+ ],
846
+ "onDelete": "cascade",
847
+ "onUpdate": "no action"
848
+ }
849
+ },
850
+ "compositePrimaryKeys": {},
851
+ "uniqueConstraints": {},
852
+ "policies": {},
853
+ "checkConstraints": {},
854
+ "isRLSEnabled": false
855
+ },
856
+ "public.package_rating": {
857
+ "name": "package_rating",
858
+ "schema": "",
859
+ "columns": {
860
+ "id": {
861
+ "name": "id",
862
+ "type": "uuid",
863
+ "primaryKey": true,
864
+ "notNull": true,
865
+ "default": "gen_random_uuid()"
866
+ },
867
+ "user_id": {
868
+ "name": "user_id",
869
+ "type": "text",
870
+ "primaryKey": false,
871
+ "notNull": true
872
+ },
873
+ "package_id": {
874
+ "name": "package_id",
875
+ "type": "uuid",
876
+ "primaryKey": false,
877
+ "notNull": true
878
+ },
879
+ "score": {
880
+ "name": "score",
881
+ "type": "integer",
882
+ "primaryKey": false,
883
+ "notNull": true
884
+ },
885
+ "created_at": {
886
+ "name": "created_at",
887
+ "type": "timestamp",
888
+ "primaryKey": false,
889
+ "notNull": true,
890
+ "default": "now()"
891
+ }
892
+ },
893
+ "indexes": {
894
+ "packageRating_packageId_idx": {
895
+ "name": "packageRating_packageId_idx",
896
+ "columns": [
897
+ {
898
+ "expression": "package_id",
899
+ "isExpression": false,
900
+ "asc": true,
901
+ "nulls": "last"
902
+ }
903
+ ],
904
+ "isUnique": false,
905
+ "concurrently": false,
906
+ "method": "btree",
907
+ "with": {}
908
+ }
909
+ },
910
+ "foreignKeys": {
911
+ "package_rating_user_id_user_id_fk": {
912
+ "name": "package_rating_user_id_user_id_fk",
913
+ "tableFrom": "package_rating",
914
+ "tableTo": "user",
915
+ "columnsFrom": [
916
+ "user_id"
917
+ ],
918
+ "columnsTo": [
919
+ "id"
920
+ ],
921
+ "onDelete": "cascade",
922
+ "onUpdate": "no action"
923
+ },
924
+ "package_rating_package_id_test_package_id_fk": {
925
+ "name": "package_rating_package_id_test_package_id_fk",
926
+ "tableFrom": "package_rating",
927
+ "tableTo": "test_package",
928
+ "columnsFrom": [
929
+ "package_id"
930
+ ],
931
+ "columnsTo": [
932
+ "id"
933
+ ],
934
+ "onDelete": "cascade",
935
+ "onUpdate": "no action"
936
+ }
937
+ },
938
+ "compositePrimaryKeys": {},
939
+ "uniqueConstraints": {
940
+ "packageRating_unique_idx": {
941
+ "name": "packageRating_unique_idx",
942
+ "nullsNotDistinct": false,
943
+ "columns": [
944
+ "user_id",
945
+ "package_id"
946
+ ]
947
+ }
948
+ },
949
+ "policies": {},
950
+ "checkConstraints": {},
951
+ "isRLSEnabled": false
952
+ },
953
+ "public.package_section": {
954
+ "name": "package_section",
955
+ "schema": "",
956
+ "columns": {
957
+ "id": {
958
+ "name": "id",
959
+ "type": "uuid",
960
+ "primaryKey": true,
961
+ "notNull": true,
962
+ "default": "gen_random_uuid()"
963
+ },
964
+ "package_id": {
965
+ "name": "package_id",
966
+ "type": "uuid",
967
+ "primaryKey": false,
968
+ "notNull": true
969
+ },
970
+ "section_type_id": {
971
+ "name": "section_type_id",
972
+ "type": "text",
973
+ "primaryKey": false,
974
+ "notNull": true
975
+ },
976
+ "title": {
977
+ "name": "title",
978
+ "type": "text",
979
+ "primaryKey": false,
980
+ "notNull": true
981
+ },
982
+ "order_index": {
983
+ "name": "order_index",
984
+ "type": "integer",
985
+ "primaryKey": false,
986
+ "notNull": true,
987
+ "default": 0
988
+ },
989
+ "created_at": {
990
+ "name": "created_at",
991
+ "type": "timestamp",
992
+ "primaryKey": false,
993
+ "notNull": true,
994
+ "default": "now()"
995
+ }
996
+ },
997
+ "indexes": {
998
+ "packageSection_packageId_idx": {
999
+ "name": "packageSection_packageId_idx",
1000
+ "columns": [
1001
+ {
1002
+ "expression": "package_id",
1003
+ "isExpression": false,
1004
+ "asc": true,
1005
+ "nulls": "last"
1006
+ }
1007
+ ],
1008
+ "isUnique": false,
1009
+ "concurrently": false,
1010
+ "method": "btree",
1011
+ "with": {}
1012
+ },
1013
+ "packageSection_sectionTypeId_idx": {
1014
+ "name": "packageSection_sectionTypeId_idx",
1015
+ "columns": [
1016
+ {
1017
+ "expression": "section_type_id",
1018
+ "isExpression": false,
1019
+ "asc": true,
1020
+ "nulls": "last"
1021
+ }
1022
+ ],
1023
+ "isUnique": false,
1024
+ "concurrently": false,
1025
+ "method": "btree",
1026
+ "with": {}
1027
+ }
1028
+ },
1029
+ "foreignKeys": {
1030
+ "package_section_package_id_test_package_id_fk": {
1031
+ "name": "package_section_package_id_test_package_id_fk",
1032
+ "tableFrom": "package_section",
1033
+ "tableTo": "test_package",
1034
+ "columnsFrom": [
1035
+ "package_id"
1036
+ ],
1037
+ "columnsTo": [
1038
+ "id"
1039
+ ],
1040
+ "onDelete": "cascade",
1041
+ "onUpdate": "no action"
1042
+ },
1043
+ "package_section_section_type_id_section_type_id_fk": {
1044
+ "name": "package_section_section_type_id_section_type_id_fk",
1045
+ "tableFrom": "package_section",
1046
+ "tableTo": "section_type",
1047
+ "columnsFrom": [
1048
+ "section_type_id"
1049
+ ],
1050
+ "columnsTo": [
1051
+ "id"
1052
+ ],
1053
+ "onDelete": "cascade",
1054
+ "onUpdate": "no action"
1055
+ }
1056
+ },
1057
+ "compositePrimaryKeys": {},
1058
+ "uniqueConstraints": {},
1059
+ "policies": {},
1060
+ "checkConstraints": {},
1061
+ "isRLSEnabled": false
1062
+ },
1063
+ "public.question": {
1064
+ "name": "question",
1065
+ "schema": "",
1066
+ "columns": {
1067
+ "id": {
1068
+ "name": "id",
1069
+ "type": "uuid",
1070
+ "primaryKey": true,
1071
+ "notNull": true,
1072
+ "default": "gen_random_uuid()"
1073
+ },
1074
+ "exam_type_id": {
1075
+ "name": "exam_type_id",
1076
+ "type": "text",
1077
+ "primaryKey": false,
1078
+ "notNull": true
1079
+ },
1080
+ "section_type_id": {
1081
+ "name": "section_type_id",
1082
+ "type": "text",
1083
+ "primaryKey": false,
1084
+ "notNull": true
1085
+ },
1086
+ "format": {
1087
+ "name": "format",
1088
+ "type": "text",
1089
+ "primaryKey": false,
1090
+ "notNull": true
1091
+ },
1092
+ "passage_text": {
1093
+ "name": "passage_text",
1094
+ "type": "text",
1095
+ "primaryKey": false,
1096
+ "notNull": true
1097
+ },
1098
+ "question_text": {
1099
+ "name": "question_text",
1100
+ "type": "text",
1101
+ "primaryKey": false,
1102
+ "notNull": true
1103
+ },
1104
+ "options": {
1105
+ "name": "options",
1106
+ "type": "jsonb",
1107
+ "primaryKey": false,
1108
+ "notNull": false
1109
+ },
1110
+ "correct_answer": {
1111
+ "name": "correct_answer",
1112
+ "type": "text",
1113
+ "primaryKey": false,
1114
+ "notNull": true
1115
+ },
1116
+ "explanation": {
1117
+ "name": "explanation",
1118
+ "type": "text",
1119
+ "primaryKey": false,
1120
+ "notNull": false
1121
+ },
1122
+ "difficulty": {
1123
+ "name": "difficulty",
1124
+ "type": "integer",
1125
+ "primaryKey": false,
1126
+ "notNull": true,
1127
+ "default": 3
1128
+ },
1129
+ "skill_tags": {
1130
+ "name": "skill_tags",
1131
+ "type": "text[]",
1132
+ "primaryKey": false,
1133
+ "notNull": false,
1134
+ "default": "'{}'"
1135
+ },
1136
+ "is_case_sensitive": {
1137
+ "name": "is_case_sensitive",
1138
+ "type": "boolean",
1139
+ "primaryKey": false,
1140
+ "notNull": true,
1141
+ "default": false
1142
+ },
1143
+ "source": {
1144
+ "name": "source",
1145
+ "type": "text",
1146
+ "primaryKey": false,
1147
+ "notNull": true,
1148
+ "default": "'manual'"
1149
+ },
1150
+ "ai_model": {
1151
+ "name": "ai_model",
1152
+ "type": "text",
1153
+ "primaryKey": false,
1154
+ "notNull": false
1155
+ },
1156
+ "ai_prompt_used": {
1157
+ "name": "ai_prompt_used",
1158
+ "type": "text",
1159
+ "primaryKey": false,
1160
+ "notNull": false
1161
+ },
1162
+ "creator_user_id": {
1163
+ "name": "creator_user_id",
1164
+ "type": "text",
1165
+ "primaryKey": false,
1166
+ "notNull": true
1167
+ },
1168
+ "is_public": {
1169
+ "name": "is_public",
1170
+ "type": "boolean",
1171
+ "primaryKey": false,
1172
+ "notNull": true,
1173
+ "default": false
1174
+ },
1175
+ "is_featured": {
1176
+ "name": "is_featured",
1177
+ "type": "boolean",
1178
+ "primaryKey": false,
1179
+ "notNull": true,
1180
+ "default": false
1181
+ },
1182
+ "usage_count": {
1183
+ "name": "usage_count",
1184
+ "type": "integer",
1185
+ "primaryKey": false,
1186
+ "notNull": true,
1187
+ "default": 0
1188
+ },
1189
+ "avg_rating": {
1190
+ "name": "avg_rating",
1191
+ "type": "integer",
1192
+ "primaryKey": false,
1193
+ "notNull": false
1194
+ },
1195
+ "created_at": {
1196
+ "name": "created_at",
1197
+ "type": "timestamp",
1198
+ "primaryKey": false,
1199
+ "notNull": true,
1200
+ "default": "now()"
1201
+ },
1202
+ "updated_at": {
1203
+ "name": "updated_at",
1204
+ "type": "timestamp",
1205
+ "primaryKey": false,
1206
+ "notNull": true,
1207
+ "default": "now()"
1208
+ }
1209
+ },
1210
+ "indexes": {
1211
+ "question_examTypeId_idx": {
1212
+ "name": "question_examTypeId_idx",
1213
+ "columns": [
1214
+ {
1215
+ "expression": "exam_type_id",
1216
+ "isExpression": false,
1217
+ "asc": true,
1218
+ "nulls": "last"
1219
+ }
1220
+ ],
1221
+ "isUnique": false,
1222
+ "concurrently": false,
1223
+ "method": "btree",
1224
+ "with": {}
1225
+ },
1226
+ "question_sectionTypeId_idx": {
1227
+ "name": "question_sectionTypeId_idx",
1228
+ "columns": [
1229
+ {
1230
+ "expression": "section_type_id",
1231
+ "isExpression": false,
1232
+ "asc": true,
1233
+ "nulls": "last"
1234
+ }
1235
+ ],
1236
+ "isUnique": false,
1237
+ "concurrently": false,
1238
+ "method": "btree",
1239
+ "with": {}
1240
+ },
1241
+ "question_creatorUserId_idx": {
1242
+ "name": "question_creatorUserId_idx",
1243
+ "columns": [
1244
+ {
1245
+ "expression": "creator_user_id",
1246
+ "isExpression": false,
1247
+ "asc": true,
1248
+ "nulls": "last"
1249
+ }
1250
+ ],
1251
+ "isUnique": false,
1252
+ "concurrently": false,
1253
+ "method": "btree",
1254
+ "with": {}
1255
+ },
1256
+ "question_isPublic_idx": {
1257
+ "name": "question_isPublic_idx",
1258
+ "columns": [
1259
+ {
1260
+ "expression": "is_public",
1261
+ "isExpression": false,
1262
+ "asc": true,
1263
+ "nulls": "last"
1264
+ }
1265
+ ],
1266
+ "isUnique": false,
1267
+ "concurrently": false,
1268
+ "method": "btree",
1269
+ "with": {}
1270
+ },
1271
+ "question_format_idx": {
1272
+ "name": "question_format_idx",
1273
+ "columns": [
1274
+ {
1275
+ "expression": "format",
1276
+ "isExpression": false,
1277
+ "asc": true,
1278
+ "nulls": "last"
1279
+ }
1280
+ ],
1281
+ "isUnique": false,
1282
+ "concurrently": false,
1283
+ "method": "btree",
1284
+ "with": {}
1285
+ },
1286
+ "question_difficulty_idx": {
1287
+ "name": "question_difficulty_idx",
1288
+ "columns": [
1289
+ {
1290
+ "expression": "difficulty",
1291
+ "isExpression": false,
1292
+ "asc": true,
1293
+ "nulls": "last"
1294
+ }
1295
+ ],
1296
+ "isUnique": false,
1297
+ "concurrently": false,
1298
+ "method": "btree",
1299
+ "with": {}
1300
+ }
1301
+ },
1302
+ "foreignKeys": {
1303
+ "question_exam_type_id_exam_type_id_fk": {
1304
+ "name": "question_exam_type_id_exam_type_id_fk",
1305
+ "tableFrom": "question",
1306
+ "tableTo": "exam_type",
1307
+ "columnsFrom": [
1308
+ "exam_type_id"
1309
+ ],
1310
+ "columnsTo": [
1311
+ "id"
1312
+ ],
1313
+ "onDelete": "cascade",
1314
+ "onUpdate": "no action"
1315
+ },
1316
+ "question_section_type_id_section_type_id_fk": {
1317
+ "name": "question_section_type_id_section_type_id_fk",
1318
+ "tableFrom": "question",
1319
+ "tableTo": "section_type",
1320
+ "columnsFrom": [
1321
+ "section_type_id"
1322
+ ],
1323
+ "columnsTo": [
1324
+ "id"
1325
+ ],
1326
+ "onDelete": "cascade",
1327
+ "onUpdate": "no action"
1328
+ },
1329
+ "question_creator_user_id_user_id_fk": {
1330
+ "name": "question_creator_user_id_user_id_fk",
1331
+ "tableFrom": "question",
1332
+ "tableTo": "user",
1333
+ "columnsFrom": [
1334
+ "creator_user_id"
1335
+ ],
1336
+ "columnsTo": [
1337
+ "id"
1338
+ ],
1339
+ "onDelete": "cascade",
1340
+ "onUpdate": "no action"
1341
+ }
1342
+ },
1343
+ "compositePrimaryKeys": {},
1344
+ "uniqueConstraints": {},
1345
+ "policies": {},
1346
+ "checkConstraints": {},
1347
+ "isRLSEnabled": false
1348
+ },
1349
+ "public.question_feedback": {
1350
+ "name": "question_feedback",
1351
+ "schema": "",
1352
+ "columns": {
1353
+ "id": {
1354
+ "name": "id",
1355
+ "type": "uuid",
1356
+ "primaryKey": true,
1357
+ "notNull": true,
1358
+ "default": "gen_random_uuid()"
1359
+ },
1360
+ "user_id": {
1361
+ "name": "user_id",
1362
+ "type": "text",
1363
+ "primaryKey": false,
1364
+ "notNull": true
1365
+ },
1366
+ "question_id": {
1367
+ "name": "question_id",
1368
+ "type": "uuid",
1369
+ "primaryKey": false,
1370
+ "notNull": true
1371
+ },
1372
+ "type": {
1373
+ "name": "type",
1374
+ "type": "text",
1375
+ "primaryKey": false,
1376
+ "notNull": true
1377
+ },
1378
+ "note": {
1379
+ "name": "note",
1380
+ "type": "text",
1381
+ "primaryKey": false,
1382
+ "notNull": false
1383
+ },
1384
+ "created_at": {
1385
+ "name": "created_at",
1386
+ "type": "timestamp",
1387
+ "primaryKey": false,
1388
+ "notNull": true,
1389
+ "default": "now()"
1390
+ }
1391
+ },
1392
+ "indexes": {
1393
+ "questionFeedback_questionId_idx": {
1394
+ "name": "questionFeedback_questionId_idx",
1395
+ "columns": [
1396
+ {
1397
+ "expression": "question_id",
1398
+ "isExpression": false,
1399
+ "asc": true,
1400
+ "nulls": "last"
1401
+ }
1402
+ ],
1403
+ "isUnique": false,
1404
+ "concurrently": false,
1405
+ "method": "btree",
1406
+ "with": {}
1407
+ }
1408
+ },
1409
+ "foreignKeys": {
1410
+ "question_feedback_user_id_user_id_fk": {
1411
+ "name": "question_feedback_user_id_user_id_fk",
1412
+ "tableFrom": "question_feedback",
1413
+ "tableTo": "user",
1414
+ "columnsFrom": [
1415
+ "user_id"
1416
+ ],
1417
+ "columnsTo": [
1418
+ "id"
1419
+ ],
1420
+ "onDelete": "cascade",
1421
+ "onUpdate": "no action"
1422
+ },
1423
+ "question_feedback_question_id_question_id_fk": {
1424
+ "name": "question_feedback_question_id_question_id_fk",
1425
+ "tableFrom": "question_feedback",
1426
+ "tableTo": "question",
1427
+ "columnsFrom": [
1428
+ "question_id"
1429
+ ],
1430
+ "columnsTo": [
1431
+ "id"
1432
+ ],
1433
+ "onDelete": "cascade",
1434
+ "onUpdate": "no action"
1435
+ }
1436
+ },
1437
+ "compositePrimaryKeys": {},
1438
+ "uniqueConstraints": {
1439
+ "questionFeedback_unique_idx": {
1440
+ "name": "questionFeedback_unique_idx",
1441
+ "nullsNotDistinct": false,
1442
+ "columns": [
1443
+ "user_id",
1444
+ "question_id"
1445
+ ]
1446
+ }
1447
+ },
1448
+ "policies": {},
1449
+ "checkConstraints": {},
1450
+ "isRLSEnabled": false
1451
+ },
1452
+ "public.question_rating": {
1453
+ "name": "question_rating",
1454
+ "schema": "",
1455
+ "columns": {
1456
+ "id": {
1457
+ "name": "id",
1458
+ "type": "uuid",
1459
+ "primaryKey": true,
1460
+ "notNull": true,
1461
+ "default": "gen_random_uuid()"
1462
+ },
1463
+ "user_id": {
1464
+ "name": "user_id",
1465
+ "type": "text",
1466
+ "primaryKey": false,
1467
+ "notNull": true
1468
+ },
1469
+ "question_id": {
1470
+ "name": "question_id",
1471
+ "type": "uuid",
1472
+ "primaryKey": false,
1473
+ "notNull": true
1474
+ },
1475
+ "score": {
1476
+ "name": "score",
1477
+ "type": "integer",
1478
+ "primaryKey": false,
1479
+ "notNull": true
1480
+ },
1481
+ "created_at": {
1482
+ "name": "created_at",
1483
+ "type": "timestamp",
1484
+ "primaryKey": false,
1485
+ "notNull": true,
1486
+ "default": "now()"
1487
+ }
1488
+ },
1489
+ "indexes": {
1490
+ "questionRating_questionId_idx": {
1491
+ "name": "questionRating_questionId_idx",
1492
+ "columns": [
1493
+ {
1494
+ "expression": "question_id",
1495
+ "isExpression": false,
1496
+ "asc": true,
1497
+ "nulls": "last"
1498
+ }
1499
+ ],
1500
+ "isUnique": false,
1501
+ "concurrently": false,
1502
+ "method": "btree",
1503
+ "with": {}
1504
+ }
1505
+ },
1506
+ "foreignKeys": {
1507
+ "question_rating_user_id_user_id_fk": {
1508
+ "name": "question_rating_user_id_user_id_fk",
1509
+ "tableFrom": "question_rating",
1510
+ "tableTo": "user",
1511
+ "columnsFrom": [
1512
+ "user_id"
1513
+ ],
1514
+ "columnsTo": [
1515
+ "id"
1516
+ ],
1517
+ "onDelete": "cascade",
1518
+ "onUpdate": "no action"
1519
+ },
1520
+ "question_rating_question_id_question_id_fk": {
1521
+ "name": "question_rating_question_id_question_id_fk",
1522
+ "tableFrom": "question_rating",
1523
+ "tableTo": "question",
1524
+ "columnsFrom": [
1525
+ "question_id"
1526
+ ],
1527
+ "columnsTo": [
1528
+ "id"
1529
+ ],
1530
+ "onDelete": "cascade",
1531
+ "onUpdate": "no action"
1532
+ }
1533
+ },
1534
+ "compositePrimaryKeys": {},
1535
+ "uniqueConstraints": {
1536
+ "questionRating_unique_idx": {
1537
+ "name": "questionRating_unique_idx",
1538
+ "nullsNotDistinct": false,
1539
+ "columns": [
1540
+ "user_id",
1541
+ "question_id"
1542
+ ]
1543
+ }
1544
+ },
1545
+ "policies": {},
1546
+ "checkConstraints": {},
1547
+ "isRLSEnabled": false
1548
+ },
1549
+ "public.section_question": {
1550
+ "name": "section_question",
1551
+ "schema": "",
1552
+ "columns": {
1553
+ "id": {
1554
+ "name": "id",
1555
+ "type": "uuid",
1556
+ "primaryKey": true,
1557
+ "notNull": true,
1558
+ "default": "gen_random_uuid()"
1559
+ },
1560
+ "section_id": {
1561
+ "name": "section_id",
1562
+ "type": "uuid",
1563
+ "primaryKey": false,
1564
+ "notNull": true
1565
+ },
1566
+ "question_id": {
1567
+ "name": "question_id",
1568
+ "type": "uuid",
1569
+ "primaryKey": false,
1570
+ "notNull": true
1571
+ },
1572
+ "order_index": {
1573
+ "name": "order_index",
1574
+ "type": "integer",
1575
+ "primaryKey": false,
1576
+ "notNull": true,
1577
+ "default": 0
1578
+ }
1579
+ },
1580
+ "indexes": {
1581
+ "sectionQuestion_sectionId_idx": {
1582
+ "name": "sectionQuestion_sectionId_idx",
1583
+ "columns": [
1584
+ {
1585
+ "expression": "section_id",
1586
+ "isExpression": false,
1587
+ "asc": true,
1588
+ "nulls": "last"
1589
+ }
1590
+ ],
1591
+ "isUnique": false,
1592
+ "concurrently": false,
1593
+ "method": "btree",
1594
+ "with": {}
1595
+ }
1596
+ },
1597
+ "foreignKeys": {
1598
+ "section_question_section_id_package_section_id_fk": {
1599
+ "name": "section_question_section_id_package_section_id_fk",
1600
+ "tableFrom": "section_question",
1601
+ "tableTo": "package_section",
1602
+ "columnsFrom": [
1603
+ "section_id"
1604
+ ],
1605
+ "columnsTo": [
1606
+ "id"
1607
+ ],
1608
+ "onDelete": "cascade",
1609
+ "onUpdate": "no action"
1610
+ },
1611
+ "section_question_question_id_question_id_fk": {
1612
+ "name": "section_question_question_id_question_id_fk",
1613
+ "tableFrom": "section_question",
1614
+ "tableTo": "question",
1615
+ "columnsFrom": [
1616
+ "question_id"
1617
+ ],
1618
+ "columnsTo": [
1619
+ "id"
1620
+ ],
1621
+ "onDelete": "cascade",
1622
+ "onUpdate": "no action"
1623
+ }
1624
+ },
1625
+ "compositePrimaryKeys": {},
1626
+ "uniqueConstraints": {
1627
+ "sectionQuestion_unique_idx": {
1628
+ "name": "sectionQuestion_unique_idx",
1629
+ "nullsNotDistinct": false,
1630
+ "columns": [
1631
+ "section_id",
1632
+ "question_id"
1633
+ ]
1634
+ }
1635
+ },
1636
+ "policies": {},
1637
+ "checkConstraints": {},
1638
+ "isRLSEnabled": false
1639
+ },
1640
+ "public.section_result": {
1641
+ "name": "section_result",
1642
+ "schema": "",
1643
+ "columns": {
1644
+ "id": {
1645
+ "name": "id",
1646
+ "type": "uuid",
1647
+ "primaryKey": true,
1648
+ "notNull": true,
1649
+ "default": "gen_random_uuid()"
1650
+ },
1651
+ "attempt_id": {
1652
+ "name": "attempt_id",
1653
+ "type": "uuid",
1654
+ "primaryKey": false,
1655
+ "notNull": true
1656
+ },
1657
+ "section_type_id": {
1658
+ "name": "section_type_id",
1659
+ "type": "text",
1660
+ "primaryKey": false,
1661
+ "notNull": true
1662
+ },
1663
+ "score": {
1664
+ "name": "score",
1665
+ "type": "integer",
1666
+ "primaryKey": false,
1667
+ "notNull": false
1668
+ },
1669
+ "max_score": {
1670
+ "name": "max_score",
1671
+ "type": "integer",
1672
+ "primaryKey": false,
1673
+ "notNull": false
1674
+ },
1675
+ "time_spent_sec": {
1676
+ "name": "time_spent_sec",
1677
+ "type": "integer",
1678
+ "primaryKey": false,
1679
+ "notNull": false
1680
+ },
1681
+ "created_at": {
1682
+ "name": "created_at",
1683
+ "type": "timestamp",
1684
+ "primaryKey": false,
1685
+ "notNull": true,
1686
+ "default": "now()"
1687
+ }
1688
+ },
1689
+ "indexes": {
1690
+ "sectionResult_attemptId_idx": {
1691
+ "name": "sectionResult_attemptId_idx",
1692
+ "columns": [
1693
+ {
1694
+ "expression": "attempt_id",
1695
+ "isExpression": false,
1696
+ "asc": true,
1697
+ "nulls": "last"
1698
+ }
1699
+ ],
1700
+ "isUnique": false,
1701
+ "concurrently": false,
1702
+ "method": "btree",
1703
+ "with": {}
1704
+ }
1705
+ },
1706
+ "foreignKeys": {
1707
+ "section_result_attempt_id_test_attempt_id_fk": {
1708
+ "name": "section_result_attempt_id_test_attempt_id_fk",
1709
+ "tableFrom": "section_result",
1710
+ "tableTo": "test_attempt",
1711
+ "columnsFrom": [
1712
+ "attempt_id"
1713
+ ],
1714
+ "columnsTo": [
1715
+ "id"
1716
+ ],
1717
+ "onDelete": "cascade",
1718
+ "onUpdate": "no action"
1719
+ },
1720
+ "section_result_section_type_id_section_type_id_fk": {
1721
+ "name": "section_result_section_type_id_section_type_id_fk",
1722
+ "tableFrom": "section_result",
1723
+ "tableTo": "section_type",
1724
+ "columnsFrom": [
1725
+ "section_type_id"
1726
+ ],
1727
+ "columnsTo": [
1728
+ "id"
1729
+ ],
1730
+ "onDelete": "cascade",
1731
+ "onUpdate": "no action"
1732
+ }
1733
+ },
1734
+ "compositePrimaryKeys": {},
1735
+ "uniqueConstraints": {},
1736
+ "policies": {},
1737
+ "checkConstraints": {},
1738
+ "isRLSEnabled": false
1739
+ },
1740
+ "public.section_type": {
1741
+ "name": "section_type",
1742
+ "schema": "",
1743
+ "columns": {
1744
+ "id": {
1745
+ "name": "id",
1746
+ "type": "text",
1747
+ "primaryKey": true,
1748
+ "notNull": true
1749
+ },
1750
+ "name": {
1751
+ "name": "name",
1752
+ "type": "text",
1753
+ "primaryKey": false,
1754
+ "notNull": true
1755
+ }
1756
+ },
1757
+ "indexes": {},
1758
+ "foreignKeys": {},
1759
+ "compositePrimaryKeys": {},
1760
+ "uniqueConstraints": {},
1761
+ "policies": {},
1762
+ "checkConstraints": {},
1763
+ "isRLSEnabled": false
1764
+ },
1765
+ "public.test_attempt": {
1766
+ "name": "test_attempt",
1767
+ "schema": "",
1768
+ "columns": {
1769
+ "id": {
1770
+ "name": "id",
1771
+ "type": "uuid",
1772
+ "primaryKey": true,
1773
+ "notNull": true,
1774
+ "default": "gen_random_uuid()"
1775
+ },
1776
+ "user_id": {
1777
+ "name": "user_id",
1778
+ "type": "text",
1779
+ "primaryKey": false,
1780
+ "notNull": true
1781
+ },
1782
+ "package_id": {
1783
+ "name": "package_id",
1784
+ "type": "uuid",
1785
+ "primaryKey": false,
1786
+ "notNull": false
1787
+ },
1788
+ "combo_id": {
1789
+ "name": "combo_id",
1790
+ "type": "uuid",
1791
+ "primaryKey": false,
1792
+ "notNull": false
1793
+ },
1794
+ "started_at": {
1795
+ "name": "started_at",
1796
+ "type": "timestamp",
1797
+ "primaryKey": false,
1798
+ "notNull": true,
1799
+ "default": "now()"
1800
+ },
1801
+ "finished_at": {
1802
+ "name": "finished_at",
1803
+ "type": "timestamp",
1804
+ "primaryKey": false,
1805
+ "notNull": false
1806
+ },
1807
+ "total_score": {
1808
+ "name": "total_score",
1809
+ "type": "integer",
1810
+ "primaryKey": false,
1811
+ "notNull": false
1812
+ },
1813
+ "max_score": {
1814
+ "name": "max_score",
1815
+ "type": "integer",
1816
+ "primaryKey": false,
1817
+ "notNull": false
1818
+ },
1819
+ "status": {
1820
+ "name": "status",
1821
+ "type": "text",
1822
+ "primaryKey": false,
1823
+ "notNull": true,
1824
+ "default": "'in_progress'"
1825
+ },
1826
+ "created_at": {
1827
+ "name": "created_at",
1828
+ "type": "timestamp",
1829
+ "primaryKey": false,
1830
+ "notNull": true,
1831
+ "default": "now()"
1832
+ }
1833
+ },
1834
+ "indexes": {
1835
+ "testAttempt_userId_idx": {
1836
+ "name": "testAttempt_userId_idx",
1837
+ "columns": [
1838
+ {
1839
+ "expression": "user_id",
1840
+ "isExpression": false,
1841
+ "asc": true,
1842
+ "nulls": "last"
1843
+ }
1844
+ ],
1845
+ "isUnique": false,
1846
+ "concurrently": false,
1847
+ "method": "btree",
1848
+ "with": {}
1849
+ },
1850
+ "testAttempt_packageId_idx": {
1851
+ "name": "testAttempt_packageId_idx",
1852
+ "columns": [
1853
+ {
1854
+ "expression": "package_id",
1855
+ "isExpression": false,
1856
+ "asc": true,
1857
+ "nulls": "last"
1858
+ }
1859
+ ],
1860
+ "isUnique": false,
1861
+ "concurrently": false,
1862
+ "method": "btree",
1863
+ "with": {}
1864
+ },
1865
+ "testAttempt_status_idx": {
1866
+ "name": "testAttempt_status_idx",
1867
+ "columns": [
1868
+ {
1869
+ "expression": "status",
1870
+ "isExpression": false,
1871
+ "asc": true,
1872
+ "nulls": "last"
1873
+ }
1874
+ ],
1875
+ "isUnique": false,
1876
+ "concurrently": false,
1877
+ "method": "btree",
1878
+ "with": {}
1879
+ }
1880
+ },
1881
+ "foreignKeys": {
1882
+ "test_attempt_user_id_user_id_fk": {
1883
+ "name": "test_attempt_user_id_user_id_fk",
1884
+ "tableFrom": "test_attempt",
1885
+ "tableTo": "user",
1886
+ "columnsFrom": [
1887
+ "user_id"
1888
+ ],
1889
+ "columnsTo": [
1890
+ "id"
1891
+ ],
1892
+ "onDelete": "cascade",
1893
+ "onUpdate": "no action"
1894
+ },
1895
+ "test_attempt_package_id_test_package_id_fk": {
1896
+ "name": "test_attempt_package_id_test_package_id_fk",
1897
+ "tableFrom": "test_attempt",
1898
+ "tableTo": "test_package",
1899
+ "columnsFrom": [
1900
+ "package_id"
1901
+ ],
1902
+ "columnsTo": [
1903
+ "id"
1904
+ ],
1905
+ "onDelete": "set null",
1906
+ "onUpdate": "no action"
1907
+ },
1908
+ "test_attempt_combo_id_combo_package_id_fk": {
1909
+ "name": "test_attempt_combo_id_combo_package_id_fk",
1910
+ "tableFrom": "test_attempt",
1911
+ "tableTo": "combo_package",
1912
+ "columnsFrom": [
1913
+ "combo_id"
1914
+ ],
1915
+ "columnsTo": [
1916
+ "id"
1917
+ ],
1918
+ "onDelete": "set null",
1919
+ "onUpdate": "no action"
1920
+ }
1921
+ },
1922
+ "compositePrimaryKeys": {},
1923
+ "uniqueConstraints": {},
1924
+ "policies": {},
1925
+ "checkConstraints": {},
1926
+ "isRLSEnabled": false
1927
+ },
1928
+ "public.test_package": {
1929
+ "name": "test_package",
1930
+ "schema": "",
1931
+ "columns": {
1932
+ "id": {
1933
+ "name": "id",
1934
+ "type": "uuid",
1935
+ "primaryKey": true,
1936
+ "notNull": true,
1937
+ "default": "gen_random_uuid()"
1938
+ },
1939
+ "title": {
1940
+ "name": "title",
1941
+ "type": "text",
1942
+ "primaryKey": false,
1943
+ "notNull": true
1944
+ },
1945
+ "description": {
1946
+ "name": "description",
1947
+ "type": "text",
1948
+ "primaryKey": false,
1949
+ "notNull": false
1950
+ },
1951
+ "exam_type_id": {
1952
+ "name": "exam_type_id",
1953
+ "type": "text",
1954
+ "primaryKey": false,
1955
+ "notNull": true
1956
+ },
1957
+ "creator_user_id": {
1958
+ "name": "creator_user_id",
1959
+ "type": "text",
1960
+ "primaryKey": false,
1961
+ "notNull": true
1962
+ },
1963
+ "is_public": {
1964
+ "name": "is_public",
1965
+ "type": "boolean",
1966
+ "primaryKey": false,
1967
+ "notNull": true,
1968
+ "default": false
1969
+ },
1970
+ "total_questions": {
1971
+ "name": "total_questions",
1972
+ "type": "integer",
1973
+ "primaryKey": false,
1974
+ "notNull": true,
1975
+ "default": 0
1976
+ },
1977
+ "total_sections": {
1978
+ "name": "total_sections",
1979
+ "type": "integer",
1980
+ "primaryKey": false,
1981
+ "notNull": true,
1982
+ "default": 0
1983
+ },
1984
+ "estimated_duration_min": {
1985
+ "name": "estimated_duration_min",
1986
+ "type": "integer",
1987
+ "primaryKey": false,
1988
+ "notNull": false
1989
+ },
1990
+ "usage_count": {
1991
+ "name": "usage_count",
1992
+ "type": "integer",
1993
+ "primaryKey": false,
1994
+ "notNull": true,
1995
+ "default": 0
1996
+ },
1997
+ "avg_rating": {
1998
+ "name": "avg_rating",
1999
+ "type": "integer",
2000
+ "primaryKey": false,
2001
+ "notNull": false
2002
+ },
2003
+ "is_featured": {
2004
+ "name": "is_featured",
2005
+ "type": "boolean",
2006
+ "primaryKey": false,
2007
+ "notNull": true,
2008
+ "default": false
2009
+ },
2010
+ "created_at": {
2011
+ "name": "created_at",
2012
+ "type": "timestamp",
2013
+ "primaryKey": false,
2014
+ "notNull": true,
2015
+ "default": "now()"
2016
+ },
2017
+ "updated_at": {
2018
+ "name": "updated_at",
2019
+ "type": "timestamp",
2020
+ "primaryKey": false,
2021
+ "notNull": true,
2022
+ "default": "now()"
2023
+ }
2024
+ },
2025
+ "indexes": {
2026
+ "testPackage_examTypeId_idx": {
2027
+ "name": "testPackage_examTypeId_idx",
2028
+ "columns": [
2029
+ {
2030
+ "expression": "exam_type_id",
2031
+ "isExpression": false,
2032
+ "asc": true,
2033
+ "nulls": "last"
2034
+ }
2035
+ ],
2036
+ "isUnique": false,
2037
+ "concurrently": false,
2038
+ "method": "btree",
2039
+ "with": {}
2040
+ },
2041
+ "testPackage_creatorUserId_idx": {
2042
+ "name": "testPackage_creatorUserId_idx",
2043
+ "columns": [
2044
+ {
2045
+ "expression": "creator_user_id",
2046
+ "isExpression": false,
2047
+ "asc": true,
2048
+ "nulls": "last"
2049
+ }
2050
+ ],
2051
+ "isUnique": false,
2052
+ "concurrently": false,
2053
+ "method": "btree",
2054
+ "with": {}
2055
+ },
2056
+ "testPackage_isPublic_idx": {
2057
+ "name": "testPackage_isPublic_idx",
2058
+ "columns": [
2059
+ {
2060
+ "expression": "is_public",
2061
+ "isExpression": false,
2062
+ "asc": true,
2063
+ "nulls": "last"
2064
+ }
2065
+ ],
2066
+ "isUnique": false,
2067
+ "concurrently": false,
2068
+ "method": "btree",
2069
+ "with": {}
2070
+ }
2071
+ },
2072
+ "foreignKeys": {
2073
+ "test_package_exam_type_id_exam_type_id_fk": {
2074
+ "name": "test_package_exam_type_id_exam_type_id_fk",
2075
+ "tableFrom": "test_package",
2076
+ "tableTo": "exam_type",
2077
+ "columnsFrom": [
2078
+ "exam_type_id"
2079
+ ],
2080
+ "columnsTo": [
2081
+ "id"
2082
+ ],
2083
+ "onDelete": "cascade",
2084
+ "onUpdate": "no action"
2085
+ },
2086
+ "test_package_creator_user_id_user_id_fk": {
2087
+ "name": "test_package_creator_user_id_user_id_fk",
2088
+ "tableFrom": "test_package",
2089
+ "tableTo": "user",
2090
+ "columnsFrom": [
2091
+ "creator_user_id"
2092
+ ],
2093
+ "columnsTo": [
2094
+ "id"
2095
+ ],
2096
+ "onDelete": "cascade",
2097
+ "onUpdate": "no action"
2098
+ }
2099
+ },
2100
+ "compositePrimaryKeys": {},
2101
+ "uniqueConstraints": {},
2102
+ "policies": {},
2103
+ "checkConstraints": {},
2104
+ "isRLSEnabled": false
2105
+ },
2106
+ "public.account": {
2107
+ "name": "account",
2108
+ "schema": "",
2109
+ "columns": {
2110
+ "id": {
2111
+ "name": "id",
2112
+ "type": "text",
2113
+ "primaryKey": true,
2114
+ "notNull": true
2115
+ },
2116
+ "account_id": {
2117
+ "name": "account_id",
2118
+ "type": "text",
2119
+ "primaryKey": false,
2120
+ "notNull": true
2121
+ },
2122
+ "provider_id": {
2123
+ "name": "provider_id",
2124
+ "type": "text",
2125
+ "primaryKey": false,
2126
+ "notNull": true
2127
+ },
2128
+ "user_id": {
2129
+ "name": "user_id",
2130
+ "type": "text",
2131
+ "primaryKey": false,
2132
+ "notNull": true
2133
+ },
2134
+ "access_token": {
2135
+ "name": "access_token",
2136
+ "type": "text",
2137
+ "primaryKey": false,
2138
+ "notNull": false
2139
+ },
2140
+ "refresh_token": {
2141
+ "name": "refresh_token",
2142
+ "type": "text",
2143
+ "primaryKey": false,
2144
+ "notNull": false
2145
+ },
2146
+ "id_token": {
2147
+ "name": "id_token",
2148
+ "type": "text",
2149
+ "primaryKey": false,
2150
+ "notNull": false
2151
+ },
2152
+ "access_token_expires_at": {
2153
+ "name": "access_token_expires_at",
2154
+ "type": "timestamp",
2155
+ "primaryKey": false,
2156
+ "notNull": false
2157
+ },
2158
+ "refresh_token_expires_at": {
2159
+ "name": "refresh_token_expires_at",
2160
+ "type": "timestamp",
2161
+ "primaryKey": false,
2162
+ "notNull": false
2163
+ },
2164
+ "scope": {
2165
+ "name": "scope",
2166
+ "type": "text",
2167
+ "primaryKey": false,
2168
+ "notNull": false
2169
+ },
2170
+ "password": {
2171
+ "name": "password",
2172
+ "type": "text",
2173
+ "primaryKey": false,
2174
+ "notNull": false
2175
+ },
2176
+ "created_at": {
2177
+ "name": "created_at",
2178
+ "type": "timestamp",
2179
+ "primaryKey": false,
2180
+ "notNull": true,
2181
+ "default": "now()"
2182
+ },
2183
+ "updated_at": {
2184
+ "name": "updated_at",
2185
+ "type": "timestamp",
2186
+ "primaryKey": false,
2187
+ "notNull": true
2188
+ }
2189
+ },
2190
+ "indexes": {
2191
+ "account_userId_idx": {
2192
+ "name": "account_userId_idx",
2193
+ "columns": [
2194
+ {
2195
+ "expression": "user_id",
2196
+ "isExpression": false,
2197
+ "asc": true,
2198
+ "nulls": "last"
2199
+ }
2200
+ ],
2201
+ "isUnique": false,
2202
+ "concurrently": false,
2203
+ "method": "btree",
2204
+ "with": {}
2205
+ }
2206
+ },
2207
+ "foreignKeys": {
2208
+ "account_user_id_user_id_fk": {
2209
+ "name": "account_user_id_user_id_fk",
2210
+ "tableFrom": "account",
2211
+ "tableTo": "user",
2212
+ "columnsFrom": [
2213
+ "user_id"
2214
+ ],
2215
+ "columnsTo": [
2216
+ "id"
2217
+ ],
2218
+ "onDelete": "cascade",
2219
+ "onUpdate": "no action"
2220
+ }
2221
+ },
2222
+ "compositePrimaryKeys": {},
2223
+ "uniqueConstraints": {},
2224
+ "policies": {},
2225
+ "checkConstraints": {},
2226
+ "isRLSEnabled": false
2227
+ },
2228
+ "public.session": {
2229
+ "name": "session",
2230
+ "schema": "",
2231
+ "columns": {
2232
+ "id": {
2233
+ "name": "id",
2234
+ "type": "text",
2235
+ "primaryKey": true,
2236
+ "notNull": true
2237
+ },
2238
+ "expires_at": {
2239
+ "name": "expires_at",
2240
+ "type": "timestamp",
2241
+ "primaryKey": false,
2242
+ "notNull": true
2243
+ },
2244
+ "token": {
2245
+ "name": "token",
2246
+ "type": "text",
2247
+ "primaryKey": false,
2248
+ "notNull": true
2249
+ },
2250
+ "created_at": {
2251
+ "name": "created_at",
2252
+ "type": "timestamp",
2253
+ "primaryKey": false,
2254
+ "notNull": true,
2255
+ "default": "now()"
2256
+ },
2257
+ "updated_at": {
2258
+ "name": "updated_at",
2259
+ "type": "timestamp",
2260
+ "primaryKey": false,
2261
+ "notNull": true
2262
+ },
2263
+ "ip_address": {
2264
+ "name": "ip_address",
2265
+ "type": "text",
2266
+ "primaryKey": false,
2267
+ "notNull": false
2268
+ },
2269
+ "user_agent": {
2270
+ "name": "user_agent",
2271
+ "type": "text",
2272
+ "primaryKey": false,
2273
+ "notNull": false
2274
+ },
2275
+ "user_id": {
2276
+ "name": "user_id",
2277
+ "type": "text",
2278
+ "primaryKey": false,
2279
+ "notNull": true
2280
+ }
2281
+ },
2282
+ "indexes": {
2283
+ "session_userId_idx": {
2284
+ "name": "session_userId_idx",
2285
+ "columns": [
2286
+ {
2287
+ "expression": "user_id",
2288
+ "isExpression": false,
2289
+ "asc": true,
2290
+ "nulls": "last"
2291
+ }
2292
+ ],
2293
+ "isUnique": false,
2294
+ "concurrently": false,
2295
+ "method": "btree",
2296
+ "with": {}
2297
+ }
2298
+ },
2299
+ "foreignKeys": {
2300
+ "session_user_id_user_id_fk": {
2301
+ "name": "session_user_id_user_id_fk",
2302
+ "tableFrom": "session",
2303
+ "tableTo": "user",
2304
+ "columnsFrom": [
2305
+ "user_id"
2306
+ ],
2307
+ "columnsTo": [
2308
+ "id"
2309
+ ],
2310
+ "onDelete": "cascade",
2311
+ "onUpdate": "no action"
2312
+ }
2313
+ },
2314
+ "compositePrimaryKeys": {},
2315
+ "uniqueConstraints": {
2316
+ "session_token_unique": {
2317
+ "name": "session_token_unique",
2318
+ "nullsNotDistinct": false,
2319
+ "columns": [
2320
+ "token"
2321
+ ]
2322
+ }
2323
+ },
2324
+ "policies": {},
2325
+ "checkConstraints": {},
2326
+ "isRLSEnabled": false
2327
+ },
2328
+ "public.user": {
2329
+ "name": "user",
2330
+ "schema": "",
2331
+ "columns": {
2332
+ "id": {
2333
+ "name": "id",
2334
+ "type": "text",
2335
+ "primaryKey": true,
2336
+ "notNull": true
2337
+ },
2338
+ "name": {
2339
+ "name": "name",
2340
+ "type": "text",
2341
+ "primaryKey": false,
2342
+ "notNull": true
2343
+ },
2344
+ "email": {
2345
+ "name": "email",
2346
+ "type": "text",
2347
+ "primaryKey": false,
2348
+ "notNull": true
2349
+ },
2350
+ "email_verified": {
2351
+ "name": "email_verified",
2352
+ "type": "boolean",
2353
+ "primaryKey": false,
2354
+ "notNull": true,
2355
+ "default": false
2356
+ },
2357
+ "image": {
2358
+ "name": "image",
2359
+ "type": "text",
2360
+ "primaryKey": false,
2361
+ "notNull": false
2362
+ },
2363
+ "role": {
2364
+ "name": "role",
2365
+ "type": "text",
2366
+ "primaryKey": false,
2367
+ "notNull": true,
2368
+ "default": "'user'"
2369
+ },
2370
+ "suspended": {
2371
+ "name": "suspended",
2372
+ "type": "boolean",
2373
+ "primaryKey": false,
2374
+ "notNull": true,
2375
+ "default": false
2376
+ },
2377
+ "created_at": {
2378
+ "name": "created_at",
2379
+ "type": "timestamp",
2380
+ "primaryKey": false,
2381
+ "notNull": true,
2382
+ "default": "now()"
2383
+ },
2384
+ "updated_at": {
2385
+ "name": "updated_at",
2386
+ "type": "timestamp",
2387
+ "primaryKey": false,
2388
+ "notNull": true,
2389
+ "default": "now()"
2390
+ }
2391
+ },
2392
+ "indexes": {},
2393
+ "foreignKeys": {},
2394
+ "compositePrimaryKeys": {},
2395
+ "uniqueConstraints": {
2396
+ "user_email_unique": {
2397
+ "name": "user_email_unique",
2398
+ "nullsNotDistinct": false,
2399
+ "columns": [
2400
+ "email"
2401
+ ]
2402
+ }
2403
+ },
2404
+ "policies": {},
2405
+ "checkConstraints": {},
2406
+ "isRLSEnabled": false
2407
+ },
2408
+ "public.verification": {
2409
+ "name": "verification",
2410
+ "schema": "",
2411
+ "columns": {
2412
+ "id": {
2413
+ "name": "id",
2414
+ "type": "text",
2415
+ "primaryKey": true,
2416
+ "notNull": true
2417
+ },
2418
+ "identifier": {
2419
+ "name": "identifier",
2420
+ "type": "text",
2421
+ "primaryKey": false,
2422
+ "notNull": true
2423
+ },
2424
+ "value": {
2425
+ "name": "value",
2426
+ "type": "text",
2427
+ "primaryKey": false,
2428
+ "notNull": true
2429
+ },
2430
+ "expires_at": {
2431
+ "name": "expires_at",
2432
+ "type": "timestamp",
2433
+ "primaryKey": false,
2434
+ "notNull": true
2435
+ },
2436
+ "created_at": {
2437
+ "name": "created_at",
2438
+ "type": "timestamp",
2439
+ "primaryKey": false,
2440
+ "notNull": true,
2441
+ "default": "now()"
2442
+ },
2443
+ "updated_at": {
2444
+ "name": "updated_at",
2445
+ "type": "timestamp",
2446
+ "primaryKey": false,
2447
+ "notNull": true,
2448
+ "default": "now()"
2449
+ }
2450
+ },
2451
+ "indexes": {
2452
+ "verification_identifier_idx": {
2453
+ "name": "verification_identifier_idx",
2454
+ "columns": [
2455
+ {
2456
+ "expression": "identifier",
2457
+ "isExpression": false,
2458
+ "asc": true,
2459
+ "nulls": "last"
2460
+ }
2461
+ ],
2462
+ "isUnique": false,
2463
+ "concurrently": false,
2464
+ "method": "btree",
2465
+ "with": {}
2466
+ }
2467
+ },
2468
+ "foreignKeys": {},
2469
+ "compositePrimaryKeys": {},
2470
+ "uniqueConstraints": {},
2471
+ "policies": {},
2472
+ "checkConstraints": {},
2473
+ "isRLSEnabled": false
2474
+ }
2475
+ },
2476
+ "enums": {},
2477
+ "schemas": {},
2478
+ "sequences": {},
2479
+ "roles": {},
2480
+ "policies": {},
2481
+ "views": {},
2482
+ "_meta": {
2483
+ "columns": {},
2484
+ "schemas": {},
2485
+ "tables": {}
2486
+ }
2487
+ }
packages/db/src/migrations/meta/_journal.json CHANGED
@@ -29,6 +29,13 @@
29
  "when": 1777620900000,
30
  "tag": "0003_repair_feedback_and_package_rating",
31
  "breakpoints": true
 
 
 
 
 
 
 
32
  }
33
  ]
34
  }
 
29
  "when": 1777620900000,
30
  "tag": "0003_repair_feedback_and_package_rating",
31
  "breakpoints": true
32
+ },
33
+ {
34
+ "idx": 4,
35
+ "version": "7",
36
+ "when": 1779604635821,
37
+ "tag": "0004_left_diamondback",
38
+ "breakpoints": true
39
  }
40
  ]
41
  }
packages/db/src/schema/app.ts CHANGED
@@ -507,7 +507,7 @@ export const generationJob = pgTable(
507
  userId: text("user_id")
508
  .notNull()
509
  .references(() => user.id, { onDelete: "cascade" }),
510
- status: text("status").notNull().default("pending"), // "pending" | "running" | "completed" | "failed" | "cancelled"
511
  mode: text("mode").notNull().default("quick"), // "quick" | "agentic"
512
  examTypeId: text("exam_type_id").notNull(),
513
  sectionTypeId: text("section_type_id").notNull(),
 
507
  userId: text("user_id")
508
  .notNull()
509
  .references(() => user.id, { onDelete: "cascade" }),
510
+ status: text("status").notNull().default("pending"), // "pending" | "running_*" | "partial_ready" | "completed" | "completed_partial" | "failed" | "cancelled"
511
  mode: text("mode").notNull().default("quick"), // "quick" | "agentic"
512
  examTypeId: text("exam_type_id").notNull(),
513
  sectionTypeId: text("section_type_id").notNull(),
packages/db/src/seed.ts CHANGED
@@ -1,6 +1,10 @@
1
- import { db } from "./index";
 
 
2
  import { examType, sectionType } from "./schema";
3
 
 
 
4
  const examTypes = [
5
  { id: "IELTS", name: "IELTS Academic", language: "English", description: "International English Language Testing System" },
6
  { id: "TOEFL", name: "TOEFL iBT", language: "English", description: "Test of English as a Foreign Language" },
 
1
+ import { drizzle } from "drizzle-orm/node-postgres";
2
+
3
+ import { loadDatabaseUrl } from "./database-url";
4
  import { examType, sectionType } from "./schema";
5
 
6
+ const db = drizzle(loadDatabaseUrl());
7
+
8
  const examTypes = [
9
  { id: "IELTS", name: "IELTS Academic", language: "English", description: "International English Language Testing System" },
10
  { id: "TOEFL", name: "TOEFL iBT", language: "English", description: "Test of English as a Foreign Language" },
turbo.json CHANGED
@@ -30,6 +30,9 @@
30
  "cache": false,
31
  "persistent": true
32
  },
 
 
 
33
  "db:studio": {
34
  "cache": false,
35
  "persistent": true
 
30
  "cache": false,
31
  "persistent": true
32
  },
33
+ "db:seed": {
34
+ "cache": false
35
+ },
36
  "db:studio": {
37
  "cache": false,
38
  "persistent": true