45 lines
1.9 KiB
SQL
45 lines
1.9 KiB
SQL
CREATE SCHEMA "form";
|
|
--> statement-breakpoint
|
|
CREATE TABLE "form"."answer" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"submission_id" text NOT NULL,
|
|
"question_id" text NOT NULL,
|
|
"value" text DEFAULT '' NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "form"."form" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"title" text NOT NULL,
|
|
"description" text,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"is_open" boolean DEFAULT true NOT NULL,
|
|
"discord_webhook_url" text,
|
|
"discord_webhook_template" text,
|
|
"discord_webhook_update_template" text
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "form"."question" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"form_id" text NOT NULL,
|
|
"type" text DEFAULT 'text' NOT NULL,
|
|
"label" text NOT NULL,
|
|
"image_url" text,
|
|
"display_order" integer DEFAULT 0 NOT NULL,
|
|
"required" boolean DEFAULT false NOT NULL,
|
|
"options" jsonb DEFAULT '[]'::jsonb,
|
|
"allow_other" boolean DEFAULT false NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "form"."submission" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"form_id" text NOT NULL,
|
|
"user_discord_id" text,
|
|
"user_name" text,
|
|
"submitted_at" timestamp DEFAULT now() NOT NULL,
|
|
"edit_history" jsonb DEFAULT '[]'::jsonb
|
|
);
|
|
--> statement-breakpoint
|
|
ALTER TABLE "form"."answer" ADD CONSTRAINT "answer_submission_id_submission_id_fk" FOREIGN KEY ("submission_id") REFERENCES "form"."submission"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "form"."answer" ADD CONSTRAINT "answer_question_id_question_id_fk" FOREIGN KEY ("question_id") REFERENCES "form"."question"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "form"."question" ADD CONSTRAINT "question_form_id_form_id_fk" FOREIGN KEY ("form_id") REFERENCES "form"."form"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "form"."submission" ADD CONSTRAINT "submission_form_id_form_id_fk" FOREIGN KEY ("form_id") REFERENCES "form"."form"("id") ON DELETE cascade ON UPDATE no action; |