refactor: migrate administrative form management to a centralized modular routing structure
This commit is contained in:
+12
-9
@@ -1,16 +1,19 @@
|
||||
import {
|
||||
pgTable,
|
||||
pgSchema,
|
||||
text,
|
||||
timestamp,
|
||||
boolean,
|
||||
integer,
|
||||
jsonb,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { uuidv7 } from "uuidv7";
|
||||
|
||||
export const forms = pgTable("form", {
|
||||
export const formSchema = pgSchema("form");
|
||||
|
||||
export const forms = formSchema.table("form", {
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
.$defaultFn(() => uuidv7()),
|
||||
title: text("title").notNull(),
|
||||
description: text("description"),
|
||||
createdAt: timestamp("created_at", { mode: "date" }).defaultNow().notNull(),
|
||||
@@ -22,10 +25,10 @@ export const forms = pgTable("form", {
|
||||
|
||||
export type QuestionType = "text" | "textarea" | "radio" | "checkbox";
|
||||
|
||||
export const questions = pgTable("question", {
|
||||
export const questions = formSchema.table("question", {
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
.$defaultFn(() => uuidv7()),
|
||||
formId: text("form_id")
|
||||
.notNull()
|
||||
.references(() => forms.id, { onDelete: "cascade" }),
|
||||
@@ -38,10 +41,10 @@ export const questions = pgTable("question", {
|
||||
allowOther: boolean("allow_other").notNull().default(false),
|
||||
});
|
||||
|
||||
export const submissions = pgTable("submission", {
|
||||
export const submissions = formSchema.table("submission", {
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
.$defaultFn(() => uuidv7()),
|
||||
formId: text("form_id")
|
||||
.notNull()
|
||||
.references(() => forms.id, { onDelete: "cascade" }),
|
||||
@@ -53,10 +56,10 @@ export const submissions = pgTable("submission", {
|
||||
.default([]),
|
||||
});
|
||||
|
||||
export const answers = pgTable("answer", {
|
||||
export const answers = formSchema.table("answer", {
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
.$defaultFn(() => uuidv7()),
|
||||
submissionId: text("submission_id")
|
||||
.notNull()
|
||||
.references(() => submissions.id, { onDelete: "cascade" }),
|
||||
|
||||
Reference in New Issue
Block a user