From fd7ffb90f59b5503a9ab6a571e12fbf2eb49577a Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sun, 13 Apr 2025 18:16:34 +0200 Subject: [PATCH] Fix item deletion hits constraint (#2097) * Fix item deletion hits constraint * Filter constraint by deletedAt --- .../20250411220921_fix_item_delete/migration.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 prisma/migrations/20250411220921_fix_item_delete/migration.sql diff --git a/prisma/migrations/20250411220921_fix_item_delete/migration.sql b/prisma/migrations/20250411220921_fix_item_delete/migration.sql new file mode 100644 index 00000000..9a171b27 --- /dev/null +++ b/prisma/migrations/20250411220921_fix_item_delete/migration.sql @@ -0,0 +1,12 @@ +-- make sure we can still delete items within 10 minutes +ALTER TABLE "Item" DROP CONSTRAINT "Item_unique_time_constraint"; +ALTER TABLE "Item" ADD CONSTRAINT "Item_unique_time_constraint" + EXCLUDE USING gist ( + "userId" WITH =, + COALESCE("parentId", -1) WITH =, + md5(COALESCE("title", '')) WITH =, + md5(COALESCE("subName", '')) WITH =, + md5(COALESCE("text", '')) WITH =, + tsrange(created_at, created_at + INTERVAL '10 minutes') WITH && + ) + WHERE (created_at > '2024-12-30' AND "deletedAt" IS NULL);