diff --git a/core/prisma/migrations/20240529145416_add_forms/migration.sql b/core/prisma/migrations/20240529145416_add_forms/migration.sql index 7ed67384c..6dc2da0de 100644 --- a/core/prisma/migrations/20240529145416_add_forms/migration.sql +++ b/core/prisma/migrations/20240529145416_add_forms/migration.sql @@ -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; \ No newline at end of file diff --git a/core/prisma/schema.prisma b/core/prisma/schema.prisma index 057e42d5f..b6ae6cbe5 100644 --- a/core/prisma/schema.prisma +++ b/core/prisma/schema.prisma @@ -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") }