diff --git a/simplex-chat.cabal b/simplex-chat.cabal index 33295929e2..12fc7497eb 100644 --- a/simplex-chat.cabal +++ b/simplex-chat.cabal @@ -138,6 +138,7 @@ library 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 + Simplex.Chat.Store.Postgres.Migrations.M20260604_simplex_name_profiles else exposed-modules: Simplex.Chat.Archive @@ -298,6 +299,7 @@ library 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 + Simplex.Chat.Store.SQLite.Migrations.M20260604_simplex_name_profiles other-modules: Paths_simplex_chat hs-source-dirs: diff --git a/src/Simplex/Chat/Store/Postgres/Migrations.hs b/src/Simplex/Chat/Store/Postgres/Migrations.hs index 319fb93717..9d7dc115d5 100644 --- a/src/Simplex/Chat/Store/Postgres/Migrations.hs +++ b/src/Simplex/Chat/Store/Postgres/Migrations.hs @@ -36,6 +36,7 @@ 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.Chat.Store.Postgres.Migrations.M20260604_simplex_name_profiles import Simplex.Messaging.Agent.Store.Shared (Migration (..)) schemaMigrations :: [(String, Text, Maybe Text)] @@ -71,7 +72,8 @@ schemaMigrations = ("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), - ("20260603_simplex_name", m20260603_simplex_name, Just down_m20260603_simplex_name) + ("20260603_simplex_name", m20260603_simplex_name, Just down_m20260603_simplex_name), + ("20260604_simplex_name_profiles", m20260604_simplex_name_profiles, Just down_m20260604_simplex_name_profiles) ] -- | The list of migrations in ascending order by date diff --git a/src/Simplex/Chat/Store/Postgres/Migrations/M20260604_simplex_name_profiles.hs b/src/Simplex/Chat/Store/Postgres/Migrations/M20260604_simplex_name_profiles.hs new file mode 100644 index 0000000000..053399a9c4 --- /dev/null +++ b/src/Simplex/Chat/Store/Postgres/Migrations/M20260604_simplex_name_profiles.hs @@ -0,0 +1,32 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes #-} + +module Simplex.Chat.Store.Postgres.Migrations.M20260604_simplex_name_profiles where + +import Data.Text (Text) +import Text.RawString.QQ (r) + +m20260604_simplex_name_profiles :: Text +m20260604_simplex_name_profiles = + [r| +ALTER TABLE contact_profiles ADD COLUMN simplex_name TEXT; +ALTER TABLE group_profiles ADD COLUMN simplex_name TEXT; + +CREATE UNIQUE INDEX idx_contact_profiles_simplex_name + ON contact_profiles(user_id, simplex_name) + WHERE simplex_name IS NOT NULL; + +CREATE UNIQUE INDEX idx_group_profiles_simplex_name + ON group_profiles(user_id, simplex_name) + WHERE simplex_name IS NOT NULL; +|] + +down_m20260604_simplex_name_profiles :: Text +down_m20260604_simplex_name_profiles = + [r| +DROP INDEX idx_group_profiles_simplex_name; +DROP INDEX idx_contact_profiles_simplex_name; + +ALTER TABLE group_profiles DROP COLUMN simplex_name; +ALTER TABLE contact_profiles DROP COLUMN simplex_name; +|] diff --git a/src/Simplex/Chat/Store/Postgres/Migrations/chat_schema.sql b/src/Simplex/Chat/Store/Postgres/Migrations/chat_schema.sql index b2096e629f..0aa2dc40b0 100644 --- a/src/Simplex/Chat/Store/Postgres/Migrations/chat_schema.sql +++ b/src/Simplex/Chat/Store/Postgres/Migrations/chat_schema.sql @@ -532,7 +532,8 @@ CREATE TABLE test_chat_schema.contact_profiles ( preferences text, contact_link bytea, short_descr text, - chat_peer_type text + chat_peer_type text, + simplex_name text ); @@ -856,7 +857,8 @@ CREATE TABLE test_chat_schema.group_profiles ( group_web_page text, group_domain text, domain_web_page bigint, - allow_embedding bigint + allow_embedding bigint, + simplex_name text ); @@ -2137,6 +2139,10 @@ CREATE INDEX idx_contact_profiles_contact_link ON test_chat_schema.contact_profi +CREATE UNIQUE INDEX idx_contact_profiles_simplex_name ON test_chat_schema.contact_profiles USING btree (user_id, simplex_name) WHERE (simplex_name IS NOT NULL); + + + CREATE INDEX idx_contact_profiles_user_id ON test_chat_schema.contact_profiles USING btree (user_id); @@ -2321,6 +2327,10 @@ CREATE INDEX idx_group_members_user_id_local_display_name ON test_chat_schema.gr +CREATE UNIQUE INDEX idx_group_profiles_simplex_name ON test_chat_schema.group_profiles USING btree (user_id, simplex_name) WHERE (simplex_name IS NOT NULL); + + + CREATE INDEX idx_group_profiles_user_id ON test_chat_schema.group_profiles USING btree (user_id); diff --git a/src/Simplex/Chat/Store/SQLite/Migrations.hs b/src/Simplex/Chat/Store/SQLite/Migrations.hs index 15f0ffb474..9269b98f80 100644 --- a/src/Simplex/Chat/Store/SQLite/Migrations.hs +++ b/src/Simplex/Chat/Store/SQLite/Migrations.hs @@ -159,6 +159,7 @@ 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.Chat.Store.SQLite.Migrations.M20260604_simplex_name_profiles import Simplex.Messaging.Agent.Store.Shared (Migration (..)) schemaMigrations :: [(String, Query, Maybe Query)] @@ -317,7 +318,8 @@ schemaMigrations = ("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), - ("20260603_simplex_name", m20260603_simplex_name, Just down_m20260603_simplex_name) + ("20260603_simplex_name", m20260603_simplex_name, Just down_m20260603_simplex_name), + ("20260604_simplex_name_profiles", m20260604_simplex_name_profiles, Just down_m20260604_simplex_name_profiles) ] -- | The list of migrations in ascending order by date diff --git a/src/Simplex/Chat/Store/SQLite/Migrations/M20260604_simplex_name_profiles.hs b/src/Simplex/Chat/Store/SQLite/Migrations/M20260604_simplex_name_profiles.hs new file mode 100644 index 0000000000..e55d3e316a --- /dev/null +++ b/src/Simplex/Chat/Store/SQLite/Migrations/M20260604_simplex_name_profiles.hs @@ -0,0 +1,31 @@ +{-# LANGUAGE QuasiQuotes #-} + +module Simplex.Chat.Store.SQLite.Migrations.M20260604_simplex_name_profiles where + +import Database.SQLite.Simple (Query) +import Database.SQLite.Simple.QQ (sql) + +m20260604_simplex_name_profiles :: Query +m20260604_simplex_name_profiles = + [sql| +ALTER TABLE contact_profiles ADD COLUMN simplex_name TEXT; +ALTER TABLE group_profiles ADD COLUMN simplex_name TEXT; + +CREATE UNIQUE INDEX idx_contact_profiles_simplex_name + ON contact_profiles(user_id, simplex_name) + WHERE simplex_name IS NOT NULL; + +CREATE UNIQUE INDEX idx_group_profiles_simplex_name + ON group_profiles(user_id, simplex_name) + WHERE simplex_name IS NOT NULL; +|] + +down_m20260604_simplex_name_profiles :: Query +down_m20260604_simplex_name_profiles = + [sql| +DROP INDEX idx_group_profiles_simplex_name; +DROP INDEX idx_contact_profiles_simplex_name; + +ALTER TABLE group_profiles DROP COLUMN simplex_name; +ALTER TABLE contact_profiles DROP COLUMN simplex_name; +|] diff --git a/src/Simplex/Chat/Store/SQLite/Migrations/chat_schema.sql b/src/Simplex/Chat/Store/SQLite/Migrations/chat_schema.sql index ae08b9e20b..79d833b044 100644 --- a/src/Simplex/Chat/Store/SQLite/Migrations/chat_schema.sql +++ b/src/Simplex/Chat/Store/SQLite/Migrations/chat_schema.sql @@ -19,7 +19,8 @@ CREATE TABLE contact_profiles( preferences TEXT, contact_link BLOB, short_descr TEXT, - chat_peer_type TEXT + chat_peer_type TEXT, + simplex_name TEXT ) STRICT; CREATE TABLE users( user_id INTEGER PRIMARY KEY, @@ -131,7 +132,8 @@ CREATE TABLE group_profiles( group_web_page TEXT, group_domain TEXT, domain_web_page INTEGER, - allow_embedding INTEGER + allow_embedding INTEGER, + simplex_name TEXT ) STRICT; CREATE TABLE groups( group_id INTEGER PRIMARY KEY, -- local group ID @@ -1322,6 +1324,18 @@ ON groups( simplex_name ) WHERE simplex_name IS NOT NULL; +CREATE UNIQUE INDEX idx_contact_profiles_simplex_name +ON contact_profiles( + user_id, + simplex_name +) +WHERE simplex_name IS NOT NULL; +CREATE UNIQUE INDEX idx_group_profiles_simplex_name +ON group_profiles( + 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