mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-15 02:40:18 +00:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user