mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-24 01:53:51 +00:00
core: member relations vector migration; set index in group for members; rework logic for avoiding duplicate introductions (#6445)
This commit is contained in:
1 parent
1101588c8b
commit
a5c6ea8e5d
17 files changed
+534
-287
No files matched your search
@@ -0,0 +1,62 @@
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Simplex.Chat.Store.Postgres.Migrations.M20251117_member_relations_vector where
|
||||
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import Text.RawString.QQ (r)
|
||||
|
||||
m20251117_member_relations_vector :: Text
|
||||
m20251117_member_relations_vector =
|
||||
T.pack
|
||||
[r|
|
||||
ALTER TABLE group_members ADD COLUMN index_in_group BIGINT NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE groups ADD COLUMN member_index BIGINT NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE group_members ADD COLUMN member_relations_vector BYTEA;
|
||||
|
||||
CREATE INDEX tmp_idx_group_members_group_id_group_member_id ON group_members(group_id, group_member_id);
|
||||
|
||||
CREATE TEMPORARY TABLE tmp_members_numbered AS
|
||||
SELECT
|
||||
group_member_id,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY group_id
|
||||
ORDER BY group_member_id ASC
|
||||
) AS rn
|
||||
FROM group_members;
|
||||
|
||||
CREATE INDEX tmp_idx_members_numbered ON tmp_members_numbered(group_member_id);
|
||||
|
||||
UPDATE group_members AS gm
|
||||
SET index_in_group = n.rn
|
||||
FROM tmp_members_numbered n
|
||||
WHERE n.group_member_id = gm.group_member_id;
|
||||
|
||||
DROP INDEX tmp_idx_group_members_group_id_group_member_id;
|
||||
DROP INDEX tmp_idx_members_numbered;
|
||||
DROP TABLE tmp_members_numbered;
|
||||
|
||||
CREATE UNIQUE INDEX idx_group_members_group_id_index_in_group ON group_members(group_id, index_in_group);
|
||||
|
||||
UPDATE groups g
|
||||
SET member_index = COALESCE((
|
||||
SELECT MAX(index_in_group)
|
||||
FROM group_members
|
||||
WHERE group_members.group_id = g.group_id
|
||||
), 0);
|
||||
|]
|
||||
|
||||
down_m20251117_member_relations_vector :: Text
|
||||
down_m20251117_member_relations_vector =
|
||||
T.pack
|
||||
[r|
|
||||
DROP INDEX idx_group_members_group_id_index_in_group;
|
||||
|
||||
ALTER TABLE group_members DROP COLUMN index_in_group;
|
||||
|
||||
ALTER TABLE groups DROP COLUMN member_index;
|
||||
|
||||
ALTER TABLE group_members DROP COLUMN member_relations_vector;
|
||||
|]
|
||||
@@ -706,7 +706,9 @@ CREATE TABLE test_chat_schema.group_members (
|
||||
support_chat_items_mentions bigint DEFAULT 0 NOT NULL,
|
||||
support_chat_last_msg_from_member_ts timestamp with time zone,
|
||||
member_xcontact_id bytea,
|
||||
member_welcome_shared_msg_id bytea
|
||||
member_welcome_shared_msg_id bytea,
|
||||
index_in_group bigint DEFAULT 0 NOT NULL,
|
||||
member_relations_vector bytea
|
||||
);
|
||||
|
||||
|
||||
@@ -805,7 +807,8 @@ CREATE TABLE test_chat_schema.groups (
|
||||
request_shared_msg_id bytea,
|
||||
conn_link_prepared_connection smallint DEFAULT 0 NOT NULL,
|
||||
via_group_link_uri bytea,
|
||||
summary_current_members_count bigint DEFAULT 0 NOT NULL
|
||||
summary_current_members_count bigint DEFAULT 0 NOT NULL,
|
||||
member_index bigint DEFAULT 0 NOT NULL
|
||||
);
|
||||
|
||||
|
||||
@@ -2081,6 +2084,10 @@ CREATE INDEX idx_group_members_group_id ON test_chat_schema.group_members USING
|
||||
|
||||
|
||||
|
||||
CREATE UNIQUE INDEX idx_group_members_group_id_index_in_group ON test_chat_schema.group_members USING btree (group_id, index_in_group);
|
||||
|
||||
|
||||
|
||||
CREATE INDEX idx_group_members_invited_by ON test_chat_schema.group_members USING btree (invited_by);
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user