Skip to content

Commit

Permalink
Ensure only one submit field per form
Browse files Browse the repository at this point in the history
  • Loading branch information
kalilsn committed May 29, 2024
1 parent b6330b3 commit 50a8342
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions core/prisma/migrations/20240529145416_add_forms/migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ ALTER TABLE "form_inputs" ADD CONSTRAINT "form_inputs_field_id_fkey" FOREIGN KEY

-- AddForeignKey
ALTER TABLE "form_inputs" ADD CONSTRAINT "form_inputs_form_id_fkey" FOREIGN KEY ("form_id") REFERENCES "forms"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- Only allow one is_submit = true column per form_id
CREATE UNIQUE INDEX form_inputs_is_submit_unique ON "form_inputs" ("form_id") WHERE "is_submit" = true;
2 changes: 1 addition & 1 deletion core/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ model FormInput {
label String
required Boolean
form Form @relation(fields: [formId], references: [id])
isSubmit Boolean @map(name: "is_submit") // TODO: add partial index so only one of these can be true per formId
isSubmit Boolean @map(name: "is_submit") // This column has a unique index preventing multiple rows with isSubmit per formId (core/prisma/migrations/20240529145416_add_forms)
@@map(name: "form_inputs")
}

0 comments on commit 50a8342

Please sign in to comment.