feat: add form schemas, modularize delete components, and migrate authentication to a dedicated database schema
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import {
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
boolean,
|
||||
integer,
|
||||
jsonb,
|
||||
} from "drizzle-orm/pg-core";
|
||||
|
||||
export const forms = pgTable("form", {
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
title: text("title").notNull(),
|
||||
description: text("description"),
|
||||
createdAt: timestamp("created_at", { mode: "date" }).defaultNow().notNull(),
|
||||
isOpen: boolean("is_open").notNull().default(true),
|
||||
discordWebhookUrl: text("discord_webhook_url"),
|
||||
discordWebhookTemplate: text("discord_webhook_template"),
|
||||
discordWebhookUpdateTemplate: text("discord_webhook_update_template"),
|
||||
});
|
||||
|
||||
export type QuestionType = "text" | "textarea" | "radio" | "checkbox";
|
||||
|
||||
export const questions = pgTable("question", {
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
formId: text("form_id")
|
||||
.notNull()
|
||||
.references(() => forms.id, { onDelete: "cascade" }),
|
||||
type: text("type").$type<QuestionType>().notNull().default("text"),
|
||||
label: text("label").notNull(),
|
||||
imageUrl: text("image_url"),
|
||||
displayOrder: integer("display_order").notNull().default(0),
|
||||
required: boolean("required").notNull().default(false),
|
||||
options: jsonb("options").$type<string[]>().default([]),
|
||||
});
|
||||
|
||||
export const submissions = pgTable("submission", {
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
formId: text("form_id")
|
||||
.notNull()
|
||||
.references(() => forms.id, { onDelete: "cascade" }),
|
||||
userDiscordId: text("user_discord_id"),
|
||||
userName: text("user_name"),
|
||||
submittedAt: timestamp("submitted_at", { mode: "date" }).defaultNow().notNull(),
|
||||
editHistory: jsonb("edit_history")
|
||||
.$type<{ editedAt: string; oldAnswers: Record<string, string> }[]>()
|
||||
.default([]),
|
||||
});
|
||||
|
||||
export const answers = pgTable("answer", {
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
submissionId: text("submission_id")
|
||||
.notNull()
|
||||
.references(() => submissions.id, { onDelete: "cascade" }),
|
||||
questionId: text("question_id")
|
||||
.notNull()
|
||||
.references(() => questions.id, { onDelete: "cascade" }),
|
||||
value: text("value").notNull().default(""),
|
||||
});
|
||||
Reference in New Issue
Block a user