Skip to content

Commit 5621627

Browse files
adaam2claude
andcommitted
fix: add organization_id IS NOT NULL to unique index WHERE clause
NULL values are treated as distinct in PostgreSQL unique indexes, so the pending invite uniqueness constraint was ineffective for orphaned rows after ON DELETE SET NULL. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 929b1ad commit 5621627

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

server/database/schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ CREATE TABLE IF NOT EXISTS team_invites (
12351235
-- Unique constraint on organization + email for non-deleted pending invites
12361236
CREATE UNIQUE INDEX IF NOT EXISTS team_invites_organization_id_email_pending_key
12371237
ON team_invites (organization_id, email)
1238-
WHERE deleted IS FALSE AND status = 'pending';
1238+
WHERE deleted IS FALSE AND status = 'pending' AND organization_id IS NOT NULL;
12391239

12401240
-- Index for looking up invites by token
12411241
CREATE UNIQUE INDEX IF NOT EXISTS team_invites_token_key

server/migrations/20260129231659_team-invites.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ CREATE TABLE "team_invites" (
1919
CONSTRAINT "team_invites_token_check" CHECK ((token <> ''::text) AND (char_length(token) <= 64))
2020
);
2121
-- Create index "team_invites_organization_id_email_pending_key" to table: "team_invites"
22-
CREATE UNIQUE INDEX "team_invites_organization_id_email_pending_key" ON "team_invites" ("organization_id", "email") WHERE ((deleted IS FALSE) AND (status = 'pending'::text));
22+
CREATE UNIQUE INDEX "team_invites_organization_id_email_pending_key" ON "team_invites" ("organization_id", "email") WHERE ((deleted IS FALSE) AND (status = 'pending'::text) AND (organization_id IS NOT NULL));
2323
-- Create index "team_invites_token_key" to table: "team_invites"
2424
CREATE UNIQUE INDEX "team_invites_token_key" ON "team_invites" ("token") WHERE (deleted IS FALSE);

server/migrations/atlas.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
h1:ZJuz4453+zjs/it/BeGleRAvbL9YdcpNBARTBbSFOEI=
1+
h1:4d6gOQGMy17apziY4ctR9d2z+f5OpvyXMfl65JF08V4=
22
20250502122425_initial-tables.sql h1:Hu3O60/bB4fjZpUay8FzyOjw6vngp087zU+U/wVKn7k=
33
20250502130852_initial-indexes.sql h1:oYbnwi9y9PPTqu7uVbSPSALhCY8XF3rv03nDfG4b7mo=
44
20250502154250_relax-http-security-fields.sql h1:0+OYIDq7IHmx7CP5BChVwfpF2rOSrRDxnqawXio2EVo=
@@ -94,4 +94,4 @@ h1:ZJuz4453+zjs/it/BeGleRAvbL9YdcpNBARTBbSFOEI=
9494
20260127183030_add_header_definitions_for_external_mcp.sql h1:zhgPD7ecRzM2VFj67jchsx0TiBLpLD4QoIvgT+7TKSw=
9595
20260129164323_install_redirect.sql h1:QK9StZ1pz4N+oRPcNYFeOx8AVt2tQBRJC+NRKJSeWOk=
9696
20260129194537_api-key-last-accessed.sql h1:2ggrS/lKJnBS6HSll9akkQg9SZSYy03W839YxU46+mU=
97-
20260129231659_team-invites.sql h1:kem7iguG/YDPGycaOkB4gtsBrHPyP1VYKRapt0Dddbg=
97+
20260129231659_team-invites.sql h1:9fsHRTPuyD+C8+KefUbSZZMHOoXuq+pCocumha6UI3A=

0 commit comments

Comments
 (0)