diff --git a/simplex-chat.cabal b/simplex-chat.cabal index 7c6f6b8bae..fc944a4072 100644 --- a/simplex-chat.cabal +++ b/simplex-chat.cabal @@ -145,9 +145,6 @@ library Simplex.Chat.Store.Postgres.Migrations.M20260601_relay_sent_web_domain Simplex.Chat.Store.Postgres.Migrations.M20260602_group_roster Simplex.Chat.Store.Postgres.Migrations.M20260603_simplex_name - Simplex.Chat.Store.Postgres.Migrations.M20260604_simplex_name_profiles - Simplex.Chat.Store.Postgres.Migrations.M20260606_simplex_name_verified - Simplex.Chat.Store.Postgres.Migrations.M20260612_smp_role_names else exposed-modules: Simplex.Chat.Archive @@ -311,9 +308,6 @@ library Simplex.Chat.Store.SQLite.Migrations.M20260601_relay_sent_web_domain Simplex.Chat.Store.SQLite.Migrations.M20260602_group_roster Simplex.Chat.Store.SQLite.Migrations.M20260603_simplex_name - Simplex.Chat.Store.SQLite.Migrations.M20260604_simplex_name_profiles - Simplex.Chat.Store.SQLite.Migrations.M20260606_simplex_name_verified - Simplex.Chat.Store.SQLite.Migrations.M20260612_smp_role_names 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 db5d46f051..e17129cd1b 100644 --- a/src/Simplex/Chat/Store/Postgres/Migrations.hs +++ b/src/Simplex/Chat/Store/Postgres/Migrations.hs @@ -39,9 +39,6 @@ import Simplex.Chat.Store.Postgres.Migrations.M20260531_member_removed_at import Simplex.Chat.Store.Postgres.Migrations.M20260601_relay_sent_web_domain import Simplex.Chat.Store.Postgres.Migrations.M20260602_group_roster import Simplex.Chat.Store.Postgres.Migrations.M20260603_simplex_name -import Simplex.Chat.Store.Postgres.Migrations.M20260604_simplex_name_profiles -import Simplex.Chat.Store.Postgres.Migrations.M20260606_simplex_name_verified -import Simplex.Chat.Store.Postgres.Migrations.M20260612_smp_role_names import Simplex.Messaging.Agent.Store.Shared (Migration (..)) schemaMigrations :: [(String, Text, Maybe Text)] @@ -80,10 +77,7 @@ schemaMigrations = ("20260531_member_removed_at", m20260531_member_removed_at, Just down_m20260531_member_removed_at), ("20260601_relay_sent_web_domain", m20260601_relay_sent_web_domain, Just down_m20260601_relay_sent_web_domain), ("20260602_group_roster", m20260602_group_roster, Just down_m20260602_group_roster), - ("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), - ("20260606_simplex_name_verified", m20260606_simplex_name_verified, Just down_m20260606_simplex_name_verified), - ("20260612_smp_role_names", m20260612_smp_role_names, Just down_m20260612_smp_role_names) + ("20260603_simplex_name", m20260603_simplex_name, Just down_m20260603_simplex_name) ] -- | The list of migrations in ascending order by date diff --git a/src/Simplex/Chat/Store/Postgres/Migrations/M20260603_simplex_name.hs b/src/Simplex/Chat/Store/Postgres/Migrations/M20260603_simplex_name.hs index f8fa467f37..049e636de6 100644 --- a/src/Simplex/Chat/Store/Postgres/Migrations/M20260603_simplex_name.hs +++ b/src/Simplex/Chat/Store/Postgres/Migrations/M20260603_simplex_name.hs @@ -17,6 +17,17 @@ import Text.RawString.QQ (r) -- connections.simplex_name and passes it to createDirectContact. After contact -- creation, contacts.simplex_name is canonical and the connection's value -- becomes a historical snapshot - it is intentionally never UPDATEd. +-- +-- contact_profiles.simplex_name and group_profiles.simplex_name hold the peer's +-- broadcast claim (received via XInfo/XGrpInfo). +-- +-- contacts.simplex_name_verified_at and groups.simplex_name_verified_at record +-- when the user last verified (via RSLV) that the peer's claimed simplex_name +-- resolves to the link stored locally. NULL means unverified; it is cleared +-- back to NULL whenever the claim changes (updateContactProfile / updateGroupProfile). +-- +-- server_operators.smp_role_names enables name resolution for an operator's SMP +-- servers (set for the simplex operator). m20260603_simplex_name :: Text m20260603_simplex_name = [r| @@ -31,14 +42,40 @@ CREATE UNIQUE INDEX idx_contacts_simplex_name CREATE UNIQUE INDEX idx_groups_simplex_name ON groups(user_id, simplex_name) WHERE simplex_name IS NOT NULL; + +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; + +ALTER TABLE contacts ADD COLUMN simplex_name_verified_at TIMESTAMPTZ; +ALTER TABLE groups ADD COLUMN simplex_name_verified_at TIMESTAMPTZ; + +ALTER TABLE server_operators ADD COLUMN smp_role_names SMALLINT NOT NULL DEFAULT 0; +UPDATE server_operators SET smp_role_names = 1 WHERE server_operator_tag = 'simplex'; |] down_m20260603_simplex_name :: Text down_m20260603_simplex_name = [r| +ALTER TABLE server_operators DROP COLUMN smp_role_names; + +ALTER TABLE groups DROP COLUMN simplex_name_verified_at; +ALTER TABLE contacts DROP COLUMN simplex_name_verified_at; + +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; + 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; diff --git a/src/Simplex/Chat/Store/SQLite/Migrations.hs b/src/Simplex/Chat/Store/SQLite/Migrations.hs index 1c1343fdd5..0cf78db595 100644 --- a/src/Simplex/Chat/Store/SQLite/Migrations.hs +++ b/src/Simplex/Chat/Store/SQLite/Migrations.hs @@ -162,9 +162,6 @@ import Simplex.Chat.Store.SQLite.Migrations.M20260531_member_removed_at import Simplex.Chat.Store.SQLite.Migrations.M20260601_relay_sent_web_domain import Simplex.Chat.Store.SQLite.Migrations.M20260602_group_roster import Simplex.Chat.Store.SQLite.Migrations.M20260603_simplex_name -import Simplex.Chat.Store.SQLite.Migrations.M20260604_simplex_name_profiles -import Simplex.Chat.Store.SQLite.Migrations.M20260606_simplex_name_verified -import Simplex.Chat.Store.SQLite.Migrations.M20260612_smp_role_names import Simplex.Messaging.Agent.Store.Shared (Migration (..)) schemaMigrations :: [(String, Query, Maybe Query)] @@ -326,10 +323,7 @@ schemaMigrations = ("20260531_member_removed_at", m20260531_member_removed_at, Just down_m20260531_member_removed_at), ("20260601_relay_sent_web_domain", m20260601_relay_sent_web_domain, Just down_m20260601_relay_sent_web_domain), ("20260602_group_roster", m20260602_group_roster, Just down_m20260602_group_roster), - ("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), - ("20260606_simplex_name_verified", m20260606_simplex_name_verified, Just down_m20260606_simplex_name_verified), - ("20260612_smp_role_names", m20260612_smp_role_names, Just down_m20260612_smp_role_names) + ("20260603_simplex_name", m20260603_simplex_name, Just down_m20260603_simplex_name) ] -- | The list of migrations in ascending order by date diff --git a/src/Simplex/Chat/Store/SQLite/Migrations/M20260603_simplex_name.hs b/src/Simplex/Chat/Store/SQLite/Migrations/M20260603_simplex_name.hs index 552808b27b..06eef6fd12 100644 --- a/src/Simplex/Chat/Store/SQLite/Migrations/M20260603_simplex_name.hs +++ b/src/Simplex/Chat/Store/SQLite/Migrations/M20260603_simplex_name.hs @@ -16,6 +16,17 @@ import Database.SQLite.Simple.QQ (sql) -- connections.simplex_name and passes it to createDirectContact. After contact -- creation, contacts.simplex_name is canonical and the connection's value -- becomes a historical snapshot - it is intentionally never UPDATEd. +-- +-- contact_profiles.simplex_name and group_profiles.simplex_name hold the peer's +-- broadcast claim (received via XInfo/XGrpInfo). +-- +-- contacts.simplex_name_verified_at and groups.simplex_name_verified_at record +-- when the user last verified (via RSLV) that the peer's claimed simplex_name +-- resolves to the link stored locally. NULL means unverified; it is cleared +-- back to NULL whenever the claim changes (updateContactProfile / updateGroupProfile). +-- +-- server_operators.smp_role_names enables name resolution for an operator's SMP +-- servers (set for the simplex operator). m20260603_simplex_name :: Query m20260603_simplex_name = [sql| @@ -30,14 +41,40 @@ CREATE UNIQUE INDEX idx_contacts_simplex_name CREATE UNIQUE INDEX idx_groups_simplex_name ON groups(user_id, simplex_name) WHERE simplex_name IS NOT NULL; + +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; + +ALTER TABLE contacts ADD COLUMN simplex_name_verified_at TEXT; +ALTER TABLE groups ADD COLUMN simplex_name_verified_at TEXT; + +ALTER TABLE server_operators ADD COLUMN smp_role_names INTEGER NOT NULL DEFAULT 0; +UPDATE server_operators SET smp_role_names = 1 WHERE server_operator_tag = 'simplex'; |] down_m20260603_simplex_name :: Query down_m20260603_simplex_name = [sql| +ALTER TABLE server_operators DROP COLUMN smp_role_names; + +ALTER TABLE groups DROP COLUMN simplex_name_verified_at; +ALTER TABLE contacts DROP COLUMN simplex_name_verified_at; + +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; + 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;