chat: simplex_name partial indexes are UNIQUE

A simplex name is a stable, per-user identity (one name → one contact
or group). Without a unique constraint, a later writer that populates
the column twice for the same name would silently produce two matching
rows, and getContactBySimplexName/getGroupInfoBySimplexName would
return whichever the planner picks first.

Promote the partial indexes added in M20260603 to UNIQUE before any
caller wires the writes. Predicate (WHERE simplex_name IS NOT NULL)
already scopes the constraint to rows that opted in.
This commit is contained in:
shum
2026-06-03 19:13:19 +00:00
parent 5df4627793
commit f71c579cf6
3 changed files with 6 additions and 6 deletions
@@ -13,11 +13,11 @@ ALTER TABLE contacts ADD COLUMN simplex_name TEXT;
ALTER TABLE groups ADD COLUMN simplex_name TEXT;
ALTER TABLE connections ADD COLUMN simplex_name TEXT;
CREATE INDEX idx_contacts_simplex_name
CREATE UNIQUE INDEX idx_contacts_simplex_name
ON contacts(user_id, simplex_name)
WHERE simplex_name IS NOT NULL;
CREATE INDEX idx_groups_simplex_name
CREATE UNIQUE INDEX idx_groups_simplex_name
ON groups(user_id, simplex_name)
WHERE simplex_name IS NOT NULL;
|]
@@ -12,11 +12,11 @@ ALTER TABLE contacts ADD COLUMN simplex_name TEXT;
ALTER TABLE groups ADD COLUMN simplex_name TEXT;
ALTER TABLE connections ADD COLUMN simplex_name TEXT;
CREATE INDEX idx_contacts_simplex_name
CREATE UNIQUE INDEX idx_contacts_simplex_name
ON contacts(user_id, simplex_name)
WHERE simplex_name IS NOT NULL;
CREATE INDEX idx_groups_simplex_name
CREATE UNIQUE INDEX idx_groups_simplex_name
ON groups(user_id, simplex_name)
WHERE simplex_name IS NOT NULL;
|]
@@ -1310,13 +1310,13 @@ ON groups(
relay_request_group_link
)
WHERE relay_request_group_link IS NOT NULL;
CREATE INDEX idx_contacts_simplex_name
CREATE UNIQUE INDEX idx_contacts_simplex_name
ON contacts(
user_id,
simplex_name
)
WHERE simplex_name IS NOT NULL;
CREATE INDEX idx_groups_simplex_name
CREATE UNIQUE INDEX idx_groups_simplex_name
ON groups(
user_id,
simplex_name