20 lines
558 B
SQL
20 lines
558 B
SQL
-- GroupUser duplicate/concurrency hardening.
|
|
--
|
|
-- Membership writes use createMany(skipDuplicates), which relies on a real
|
|
-- user/group uniqueness constraint rather than application-side de-duping alone.
|
|
|
|
DO $$
|
|
BEGIN
|
|
IF EXISTS (
|
|
SELECT 1
|
|
FROM "GroupUser"
|
|
GROUP BY "groupId", "userId"
|
|
HAVING COUNT(*) > 1
|
|
) THEN
|
|
RAISE EXCEPTION 'Cannot add GroupUser membership uniqueness: duplicate groupId/userId rows exist';
|
|
END IF;
|
|
END $$;
|
|
|
|
CREATE UNIQUE INDEX IF NOT EXISTS "group_user_membership_key"
|
|
ON "GroupUser" ("groupId", "userId");
|