refactor(store): consolidate names migrations into one

Unshipped feature - merge the four incremental simplex_name migrations
(0603/0604/0606/0612) into a single M20260603_simplex_name. The combined
UP applies the ALTERs/indexes in the same order, so the resulting schema
is byte-identical (verified by SchemaDump on SQLite and pg_dump on Postgres).
This commit is contained in:
shum
2026-06-23 16:23:02 +00:00
parent 60258245eb
commit 0706b2516e
5 changed files with 78 additions and 22 deletions
-6
View File
@@ -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:
@@ -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
@@ -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;
+1 -7
View File
@@ -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
@@ -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;