chat: migration adds simplex_name to contacts, groups, connections

Nullable TEXT column on all three tables, with partial indexes on
contacts(user_id, simplex_name) and groups(user_id, simplex_name)
for the upcoming connectPlanName lookup. connections.simplex_name
is the transient carrier from APIConnect -> XInfo handler, where
the value is copied to contacts.simplex_name at delayed create.
No reads or writes yet - column threading lands in subsequent commits.
This commit is contained in:
shum
2026-06-03 15:04:56 +00:00
parent ee0a45e9c5
commit 5e15e6eac8
7 changed files with 105 additions and 6 deletions
+2
View File
@@ -137,6 +137,7 @@ library
Simplex.Chat.Store.Postgres.Migrations.M20260529_delivery_job_senders
Simplex.Chat.Store.Postgres.Migrations.M20260530_client_services
Simplex.Chat.Store.Postgres.Migrations.M20260531_member_removed_at
Simplex.Chat.Store.Postgres.Migrations.M20260603_simplex_name
else
exposed-modules:
Simplex.Chat.Archive
@@ -296,6 +297,7 @@ library
Simplex.Chat.Store.SQLite.Migrations.M20260529_delivery_job_senders
Simplex.Chat.Store.SQLite.Migrations.M20260530_client_services
Simplex.Chat.Store.SQLite.Migrations.M20260531_member_removed_at
Simplex.Chat.Store.SQLite.Migrations.M20260603_simplex_name
other-modules:
Paths_simplex_chat
hs-source-dirs:
@@ -35,6 +35,7 @@ import Simplex.Chat.Store.Postgres.Migrations.M20260515_public_group_access
import Simplex.Chat.Store.Postgres.Migrations.M20260529_delivery_job_senders
import Simplex.Chat.Store.Postgres.Migrations.M20260530_client_services
import Simplex.Chat.Store.Postgres.Migrations.M20260531_member_removed_at
import Simplex.Chat.Store.Postgres.Migrations.M20260603_simplex_name
import Simplex.Messaging.Agent.Store.Shared (Migration (..))
schemaMigrations :: [(String, Text, Maybe Text)]
@@ -69,7 +70,8 @@ schemaMigrations =
("20260515_public_group_access", m20260515_public_group_access, Just down_m20260515_public_group_access),
("20260529_delivery_job_senders", m20260529_delivery_job_senders, Just down_m20260529_delivery_job_senders),
("20260530_client_services", m20260530_client_services, Just down_m20260530_client_services),
("20260531_member_removed_at", m20260531_member_removed_at, Just down_m20260531_member_removed_at)
("20260531_member_removed_at", m20260531_member_removed_at, Just down_m20260531_member_removed_at),
("20260603_simplex_name", m20260603_simplex_name, Just down_m20260603_simplex_name)
]
-- | The list of migrations in ascending order by date
@@ -0,0 +1,34 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module Simplex.Chat.Store.Postgres.Migrations.M20260603_simplex_name where
import Data.Text (Text)
import Text.RawString.QQ (r)
m20260603_simplex_name :: Text
m20260603_simplex_name =
[r|
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
ON contacts(user_id, simplex_name)
WHERE simplex_name IS NOT NULL;
CREATE INDEX idx_groups_simplex_name
ON groups(user_id, simplex_name)
WHERE simplex_name IS NOT NULL;
|]
down_m20260603_simplex_name :: Text
down_m20260603_simplex_name =
[r|
DROP INDEX idx_groups_simplex_name;
DROP INDEX idx_contacts_simplex_name;
ALTER TABLE connections DROP COLUMN simplex_name;
ALTER TABLE groups DROP COLUMN simplex_name;
ALTER TABLE contacts DROP COLUMN simplex_name;
|]
@@ -482,7 +482,8 @@ CREATE TABLE test_chat_schema.connections (
short_link_inv bytea,
via_short_link_contact bytea,
via_contact_uri bytea,
relay_test smallint DEFAULT 0 NOT NULL
relay_test smallint DEFAULT 0 NOT NULL,
simplex_name text
);
@@ -612,7 +613,8 @@ CREATE TABLE test_chat_schema.contacts (
grp_direct_inv_from_group_id bigint,
grp_direct_inv_from_group_member_id bigint,
grp_direct_inv_from_member_conn_id bigint,
grp_direct_inv_started_connection smallint DEFAULT 0 NOT NULL
grp_direct_inv_started_connection smallint DEFAULT 0 NOT NULL,
simplex_name text
);
@@ -969,7 +971,8 @@ CREATE TABLE test_chat_schema.groups (
relay_request_retries bigint DEFAULT 0 NOT NULL,
relay_request_delay bigint DEFAULT 0 NOT NULL,
relay_request_execute_at timestamp with time zone DEFAULT '1970-01-01 01:00:00+01'::timestamp with time zone NOT NULL,
relay_inactive_at timestamp with time zone
relay_inactive_at timestamp with time zone,
simplex_name text
);
@@ -2190,6 +2193,10 @@ CREATE INDEX idx_contacts_grp_direct_inv_from_member_conn_id ON test_chat_schema
CREATE INDEX idx_contacts_simplex_name ON test_chat_schema.contacts USING btree (user_id, simplex_name) WHERE (simplex_name IS NOT NULL);
CREATE INDEX idx_contacts_xcontact_id ON test_chat_schema.contacts USING btree (xcontact_id);
@@ -2366,6 +2373,10 @@ CREATE INDEX idx_groups_relay_request_group_link ON test_chat_schema.groups USIN
CREATE INDEX idx_groups_simplex_name ON test_chat_schema.groups USING btree (user_id, simplex_name) WHERE (simplex_name IS NOT NULL);
CREATE INDEX idx_groups_summary_current_members_count ON test_chat_schema.groups USING btree (summary_current_members_count);
+3 -1
View File
@@ -158,6 +158,7 @@ import Simplex.Chat.Store.SQLite.Migrations.M20260515_public_group_access
import Simplex.Chat.Store.SQLite.Migrations.M20260529_delivery_job_senders
import Simplex.Chat.Store.SQLite.Migrations.M20260530_client_services
import Simplex.Chat.Store.SQLite.Migrations.M20260531_member_removed_at
import Simplex.Chat.Store.SQLite.Migrations.M20260603_simplex_name
import Simplex.Messaging.Agent.Store.Shared (Migration (..))
schemaMigrations :: [(String, Query, Maybe Query)]
@@ -315,7 +316,8 @@ schemaMigrations =
("20260515_public_group_access", m20260515_public_group_access, Just down_m20260515_public_group_access),
("20260529_delivery_job_senders", m20260529_delivery_job_senders, Just down_m20260529_delivery_job_senders),
("20260530_client_services", m20260530_client_services, Just down_m20260530_client_services),
("20260531_member_removed_at", m20260531_member_removed_at, Just down_m20260531_member_removed_at)
("20260531_member_removed_at", m20260531_member_removed_at, Just down_m20260531_member_removed_at),
("20260603_simplex_name", m20260603_simplex_name, Just down_m20260603_simplex_name)
]
-- | The list of migrations in ascending order by date
@@ -0,0 +1,33 @@
{-# LANGUAGE QuasiQuotes #-}
module Simplex.Chat.Store.SQLite.Migrations.M20260603_simplex_name where
import Database.SQLite.Simple (Query)
import Database.SQLite.Simple.QQ (sql)
m20260603_simplex_name :: Query
m20260603_simplex_name =
[sql|
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
ON contacts(user_id, simplex_name)
WHERE simplex_name IS NOT NULL;
CREATE INDEX idx_groups_simplex_name
ON groups(user_id, simplex_name)
WHERE simplex_name IS NOT NULL;
|]
down_m20260603_simplex_name :: Query
down_m20260603_simplex_name =
[sql|
DROP INDEX idx_groups_simplex_name;
DROP INDEX idx_contacts_simplex_name;
ALTER TABLE connections DROP COLUMN simplex_name;
ALTER TABLE groups DROP COLUMN simplex_name;
ALTER TABLE contacts DROP COLUMN simplex_name;
|]
@@ -92,6 +92,7 @@ CREATE TABLE contacts(
grp_direct_inv_from_group_member_id INTEGER REFERENCES group_members(group_member_id) ON DELETE SET NULL,
grp_direct_inv_from_member_conn_id INTEGER REFERENCES connections(connection_id) ON DELETE SET NULL,
grp_direct_inv_started_connection INTEGER NOT NULL DEFAULT 0,
simplex_name TEXT,
FOREIGN KEY(user_id, local_display_name)
REFERENCES display_names(user_id, local_display_name)
ON DELETE CASCADE
@@ -182,7 +183,8 @@ CREATE TABLE groups(
relay_request_retries INTEGER NOT NULL DEFAULT 0,
relay_request_delay INTEGER NOT NULL DEFAULT 0,
relay_request_execute_at TEXT NOT NULL DEFAULT '1970-01-01 00:00:00',
relay_inactive_at TEXT, -- received
relay_inactive_at TEXT,
simplex_name TEXT, -- received
FOREIGN KEY(user_id, local_display_name)
REFERENCES display_names(user_id, local_display_name)
ON DELETE CASCADE
@@ -351,6 +353,7 @@ CREATE TABLE connections(
via_short_link_contact BLOB,
via_contact_uri BLOB,
relay_test INTEGER NOT NULL DEFAULT 0,
simplex_name TEXT,
FOREIGN KEY(snd_file_id, connection_id)
REFERENCES snd_files(file_id, connection_id)
ON DELETE CASCADE
@@ -1307,6 +1310,18 @@ ON groups(
relay_request_group_link
)
WHERE relay_request_group_link IS NOT NULL;
CREATE INDEX idx_contacts_simplex_name
ON contacts(
user_id,
simplex_name
)
WHERE simplex_name IS NOT NULL;
CREATE INDEX idx_groups_simplex_name
ON groups(
user_id,
simplex_name
)
WHERE simplex_name IS NOT NULL;
CREATE TRIGGER on_group_members_insert_update_summary
AFTER INSERT ON group_members
FOR EACH ROW