chat: exclude soft-deleted contacts from idx_contacts_simplex_name

The lookup `getContactBySimplexName` (Store/Direct.hs:781) filters
`AND deleted = 0`, but the index predicate `WHERE simplex_name IS NOT
NULL` covered tombstoned rows too. Forward-compat trap: once writers
land a non-Nothing simplex_name, soft-deleting a contact would block
re-claiming its name (UNIQUE conflict) even though the lookup reports
the slot as free.

Tighten the partial-index predicate to also require deleted = 0 so the
constraint scope matches the live-lookup scope. Groups have no soft-
delete column, so their index stays as-is.
This commit is contained in:
shum
2026-06-03 19:35:19 +00:00
parent 43503a7ef1
commit 98fb416165
4 changed files with 4 additions and 4 deletions
@@ -15,7 +15,7 @@ ALTER TABLE connections ADD COLUMN simplex_name TEXT;
CREATE UNIQUE INDEX idx_contacts_simplex_name
ON contacts(user_id, simplex_name)
WHERE simplex_name IS NOT NULL;
WHERE simplex_name IS NOT NULL AND deleted = 0;
CREATE UNIQUE INDEX idx_groups_simplex_name
ON groups(user_id, simplex_name)
@@ -2193,7 +2193,7 @@ CREATE INDEX idx_contacts_grp_direct_inv_from_member_conn_id ON test_chat_schema
CREATE UNIQUE INDEX idx_contacts_simplex_name ON test_chat_schema.contacts USING btree (user_id, simplex_name) WHERE (simplex_name IS NOT NULL);
CREATE UNIQUE INDEX idx_contacts_simplex_name ON test_chat_schema.contacts USING btree (user_id, simplex_name) WHERE ((simplex_name IS NOT NULL) AND (deleted = 0));
@@ -14,7 +14,7 @@ ALTER TABLE connections ADD COLUMN simplex_name TEXT;
CREATE UNIQUE INDEX idx_contacts_simplex_name
ON contacts(user_id, simplex_name)
WHERE simplex_name IS NOT NULL;
WHERE simplex_name IS NOT NULL AND deleted = 0;
CREATE UNIQUE INDEX idx_groups_simplex_name
ON groups(user_id, simplex_name)
@@ -1315,7 +1315,7 @@ ON contacts(
user_id,
simplex_name
)
WHERE simplex_name IS NOT NULL;
WHERE simplex_name IS NOT NULL AND deleted = 0;
CREATE UNIQUE INDEX idx_groups_simplex_name
ON groups(
user_id,