mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-01 00:56:05 +00:00
fix migration
This commit is contained in:
@@ -111,6 +111,7 @@ library
|
||||
Simplex.Chat.Migrations.M20230827_file_encryption
|
||||
Simplex.Chat.Migrations.M20230829_connections_chat_vrange
|
||||
Simplex.Chat.Migrations.M20230903_connections_to_subscribe
|
||||
Simplex.Chat.Migrations.M20230914_member_probes
|
||||
Simplex.Chat.Mobile
|
||||
Simplex.Chat.Mobile.File
|
||||
Simplex.Chat.Mobile.Shared
|
||||
|
||||
@@ -3201,10 +3201,10 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do
|
||||
case ct_ of
|
||||
Nothing -> do
|
||||
let connectedIncognito = memberIncognito membership
|
||||
when (memberCategory m == GCPreMember) $ probeMatchingContacts ct connectedIncognito
|
||||
when (memberCategory m == GCPreMember) $ probeMatchingMemberContact m connectedIncognito
|
||||
Just ct -> do
|
||||
let connectedIncognito = contactConnIncognito ct || memberIncognito membership
|
||||
when (memberCategory m == GCPreMember) $ probeMatchingMemberContact m connectedIncognito
|
||||
when (memberCategory m == GCPreMember) $ probeMatchingContacts ct connectedIncognito
|
||||
-- >>= \case
|
||||
-- Nothing -> do
|
||||
-- notifyMemberConnected gInfo m Nothing
|
||||
|
||||
@@ -5,94 +5,51 @@ module Simplex.Chat.Migrations.M20230914_member_probes where
|
||||
import Database.SQLite.Simple (Query)
|
||||
import Database.SQLite.Simple.QQ (sql)
|
||||
|
||||
m20230903_connections_to_subscribe :: Query
|
||||
m20230903_connections_to_subscribe =
|
||||
m20230914_member_probes :: Query
|
||||
m20230914_member_probes =
|
||||
[sql|
|
||||
-- sent_probes
|
||||
ALTER TABLE sent_probes ADD COLUMN probe_contact_id INTEGER UNIQUE REFERENCES contacts ON DELETE CASCADE;
|
||||
ALTER TABLE sent_probes ADD COLUMN probe_group_member_id INTEGER UNIQUE REFERENCES group_members ON DELETE CASCADE;
|
||||
ALTER TABLE sent_probes ADD COLUMN probe_contact_id INTEGER REFERENCES contacts(contact_id) ON DELETE CASCADE;
|
||||
ALTER TABLE sent_probes ADD COLUMN probe_group_member_id INTEGER REFERENCES group_members(group_member_id) ON DELETE CASCADE;
|
||||
UPDATE sent_probes SET probe_contact_id = contact_id;
|
||||
|
||||
ALTER TABLE sent_probes DROP COLUMN contact_id;
|
||||
-- ALTER TABLE sent_probes DROP COLUMN contact_id;
|
||||
|
||||
CREATE INDEX idx_sent_probes_user_id ON sent_probes(user_id);
|
||||
CREATE INDEX idx_sent_probes_probe_contact_id ON sent_probes(probe_contact_id);
|
||||
CREATE INDEX idx_sent_probes_probe_group_member_id ON sent_probes(probe_group_member_id);
|
||||
|
||||
-- sent_probe_hashes
|
||||
ALTER TABLE sent_probe_hashes ADD COLUMN probe_contact_id INTEGER UNIQUE REFERENCES contacts ON DELETE CASCADE,
|
||||
ALTER TABLE sent_probe_hashes ADD COLUMN probe_group_member_id INTEGER UNIQUE REFERENCES group_members ON DELETE CASCADE,
|
||||
UPDATE sent_probe_hashes SET probe_contact_id = contact_id;
|
||||
|
||||
DROP INDEX idx_sent_probe_hashes_contact_id ON sent_probe_hashes(contact_id);
|
||||
ALTER TABLE sent_probe_hashes DROP COLUMN contact_id;
|
||||
|
||||
CREATE INDEX idx_sent_probe_hashes_probe_contact_id ON sent_probe_hashes(probe_contact_id);
|
||||
CREATE INDEX idx_sent_probe_hashes_probe_group_member_id ON sent_probe_hashes(probe_group_member_id);
|
||||
CREATE UNIQUE INDEX idx_sent_probes_probe_contact_id ON sent_probes(probe_contact_id);
|
||||
CREATE UNIQUE INDEX idx_sent_probes_probe_group_member_id ON sent_probes(probe_group_member_id);
|
||||
CREATE INDEX idx_sent_probes_probe ON sent_probes(probe);
|
||||
|
||||
-- received_probes
|
||||
ALTER TABLE received_probes ADD COLUMN probe_contact_id INTEGER UNIQUE REFERENCES contacts ON DELETE CASCADE,
|
||||
ALTER TABLE received_probes ADD COLUMN probe_group_member_id INTEGER UNIQUE REFERENCES group_members ON DELETE CASCADE,
|
||||
ALTER TABLE received_probes ADD COLUMN probe_contact_id INTEGER REFERENCES contacts(contact_id) ON DELETE CASCADE;
|
||||
ALTER TABLE received_probes ADD COLUMN probe_group_member_id INTEGER REFERENCES group_members(group_member_id) ON DELETE CASCADE;
|
||||
UPDATE received_probes SET probe_contact_id = contact_id;
|
||||
|
||||
DROP INDEX idx_received_probes_contact_id ON received_probes(contact_id);
|
||||
ALTER TABLE received_probes DROP COLUMN contact_id;
|
||||
DROP INDEX idx_received_probes_contact_id;
|
||||
-- ALTER TABLE received_probes DROP COLUMN contact_id;
|
||||
|
||||
CREATE INDEX idx_received_probes_probe_contact_id ON received_probes(probe_contact_id);
|
||||
CREATE INDEX idx_received_probes_probe_group_member_id ON received_probes(probe_group_member_id);
|
||||
CREATE UNIQUE INDEX idx_received_probes_probe_contact_id ON received_probes(probe_contact_id);
|
||||
CREATE UNIQUE INDEX idx_received_probes_probe_group_member_id ON received_probes(probe_group_member_id);
|
||||
CREATE INDEX idx_received_probes_probe_hash ON received_probes(probe_hash);
|
||||
|]
|
||||
|
||||
down_m20230903_connections_to_subscribe :: Query
|
||||
down_m20230903_connections_to_subscribe =
|
||||
down_m20230914_member_probes :: Query
|
||||
down_m20230914_member_probes =
|
||||
[sql|
|
||||
DROP INDEX idx_sent_probes_user_id;
|
||||
DROP INDEX idx_sent_probes_probe_contact_id;
|
||||
DROP INDEX idx_sent_probes_probe_group_member_id;
|
||||
-- DROP INDEX idx_sent_probe_hashes_probe_contact_id;
|
||||
DROP INDEX idx_sent_probe_hashes_probe_group_member_id;
|
||||
-- DROP INDEX idx_received_probes_probe_contact_id;
|
||||
DROP INDEX idx_sent_probes_probe;
|
||||
|
||||
DROP INDEX idx_received_probes_probe_contact_id;
|
||||
DROP INDEX idx_received_probes_probe_group_member_id;
|
||||
DROP INDEX idx_received_probes_probe_hash;
|
||||
|
||||
DELETE FROM sent_probes WHERE probe_contact_id IS NULL;
|
||||
DELETE FROM sent_probe_hashes WHERE probe_contact_id IS NULL;
|
||||
DELETE FROM received_probes WHERE probe_contact_id IS NULL;
|
||||
|
||||
ALTER TABLE sent_probes RENAME COLUMN probe_contact_id TO contact_id;
|
||||
ALTER TABLE sent_probe_hashes RENAME COLUMN probe_contact_id TO contact_id;
|
||||
ALTER TABLE received_probes RENAME COLUMN probe_contact_id TO contact_id;
|
||||
-- ALTER TABLE sent_probes RENAME COLUMN probe_contact_id TO contact_id;
|
||||
-- ALTER TABLE received_probes RENAME COLUMN probe_contact_id TO contact_id;
|
||||
|
||||
CREATE INDEX idx_received_probes_user_id ON received_probes(user_id);
|
||||
-- CREATE INDEX idx_received_probes_contact_id ON received_probes(contact_id);
|
||||
CREATE INDEX idx_sent_probe_hashes_user_id ON sent_probe_hashes(user_id);
|
||||
-- CREATE INDEX idx_sent_probe_hashes_contact_id ON sent_probe_hashes(contact_id);
|
||||
CREATE INDEX idx_received_probes_contact_id ON received_probes(contact_id);
|
||||
|]
|
||||
|
||||
|
||||
CREATE TABLE sent_probes(
|
||||
sent_probe_id INTEGER PRIMARY KEY,
|
||||
contact_id INTEGER NOT NULL UNIQUE REFERENCES contacts ON DELETE CASCADE,
|
||||
probe BLOB NOT NULL,
|
||||
user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE,
|
||||
created_at TEXT CHECK(created_at NOT NULL),
|
||||
updated_at TEXT CHECK(updated_at NOT NULL),
|
||||
UNIQUE(user_id, probe)
|
||||
);
|
||||
CREATE TABLE sent_probe_hashes(
|
||||
sent_probe_hash_id INTEGER PRIMARY KEY,
|
||||
sent_probe_id INTEGER NOT NULL REFERENCES sent_probes ON DELETE CASCADE,
|
||||
contact_id INTEGER NOT NULL REFERENCES contacts ON DELETE CASCADE,
|
||||
user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE,
|
||||
created_at TEXT CHECK(created_at NOT NULL),
|
||||
updated_at TEXT CHECK(updated_at NOT NULL),
|
||||
UNIQUE(sent_probe_id, contact_id)
|
||||
);
|
||||
CREATE TABLE received_probes(
|
||||
received_probe_id INTEGER PRIMARY KEY,
|
||||
contact_id INTEGER NOT NULL REFERENCES contacts ON DELETE CASCADE,
|
||||
probe BLOB,
|
||||
probe_hash BLOB NOT NULL,
|
||||
user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE
|
||||
,
|
||||
created_at TEXT CHECK(created_at NOT NULL),
|
||||
updated_at TEXT CHECK(updated_at NOT NULL)
|
||||
);
|
||||
@@ -82,6 +82,8 @@ CREATE TABLE sent_probes(
|
||||
user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE,
|
||||
created_at TEXT CHECK(created_at NOT NULL),
|
||||
updated_at TEXT CHECK(updated_at NOT NULL),
|
||||
probe_contact_id INTEGER REFERENCES contacts(contact_id) ON DELETE CASCADE,
|
||||
probe_group_member_id INTEGER REFERENCES group_members(group_member_id) ON DELETE CASCADE,
|
||||
UNIQUE(user_id, probe)
|
||||
);
|
||||
CREATE TABLE sent_probe_hashes(
|
||||
@@ -101,7 +103,9 @@ CREATE TABLE received_probes(
|
||||
user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE
|
||||
,
|
||||
created_at TEXT CHECK(created_at NOT NULL),
|
||||
updated_at TEXT CHECK(updated_at NOT NULL)
|
||||
updated_at TEXT CHECK(updated_at NOT NULL),
|
||||
probe_contact_id INTEGER REFERENCES contacts(contact_id) ON DELETE CASCADE,
|
||||
probe_group_member_id INTEGER REFERENCES group_members(group_member_id) ON DELETE CASCADE
|
||||
);
|
||||
CREATE TABLE known_servers(
|
||||
server_id INTEGER PRIMARY KEY,
|
||||
@@ -625,7 +629,6 @@ CREATE INDEX idx_pending_group_messages_group_member_id ON pending_group_message
|
||||
CREATE INDEX idx_rcv_file_chunks_file_id ON rcv_file_chunks(file_id);
|
||||
CREATE INDEX idx_rcv_files_group_member_id ON rcv_files(group_member_id);
|
||||
CREATE INDEX idx_received_probes_user_id ON received_probes(user_id);
|
||||
CREATE INDEX idx_received_probes_contact_id ON received_probes(contact_id);
|
||||
CREATE INDEX idx_sent_probe_hashes_user_id ON sent_probe_hashes(user_id);
|
||||
CREATE INDEX idx_sent_probe_hashes_contact_id ON sent_probe_hashes(contact_id);
|
||||
CREATE INDEX idx_settings_user_id ON settings(user_id);
|
||||
@@ -713,3 +716,18 @@ CREATE INDEX idx_chat_items_user_id_item_status ON chat_items(
|
||||
item_status
|
||||
);
|
||||
CREATE INDEX idx_connections_to_subscribe ON connections(to_subscribe);
|
||||
CREATE INDEX idx_sent_probes_user_id ON sent_probes(user_id);
|
||||
CREATE UNIQUE INDEX idx_sent_probes_probe_contact_id ON sent_probes(
|
||||
probe_contact_id
|
||||
);
|
||||
CREATE UNIQUE INDEX idx_sent_probes_probe_group_member_id ON sent_probes(
|
||||
probe_group_member_id
|
||||
);
|
||||
CREATE INDEX idx_sent_probes_probe ON sent_probes(probe);
|
||||
CREATE UNIQUE INDEX idx_received_probes_probe_contact_id ON received_probes(
|
||||
probe_contact_id
|
||||
);
|
||||
CREATE UNIQUE INDEX idx_received_probes_probe_group_member_id ON received_probes(
|
||||
probe_group_member_id
|
||||
);
|
||||
CREATE INDEX idx_received_probes_probe_hash ON received_probes(probe_hash);
|
||||
|
||||
@@ -79,6 +79,7 @@ import Simplex.Chat.Migrations.M20230814_indexes
|
||||
import Simplex.Chat.Migrations.M20230827_file_encryption
|
||||
import Simplex.Chat.Migrations.M20230829_connections_chat_vrange
|
||||
import Simplex.Chat.Migrations.M20230903_connections_to_subscribe
|
||||
import Simplex.Chat.Migrations.M20230914_member_probes
|
||||
import Simplex.Messaging.Agent.Store.SQLite.Migrations (Migration (..))
|
||||
|
||||
schemaMigrations :: [(String, Query, Maybe Query)]
|
||||
@@ -157,7 +158,8 @@ schemaMigrations =
|
||||
("20230814_indexes", m20230814_indexes, Just down_m20230814_indexes),
|
||||
("20230827_file_encryption", m20230827_file_encryption, Just down_m20230827_file_encryption),
|
||||
("20230829_connections_chat_vrange", m20230829_connections_chat_vrange, Just down_m20230829_connections_chat_vrange),
|
||||
("20230903_connections_to_subscribe", m20230903_connections_to_subscribe, Just down_m20230903_connections_to_subscribe)
|
||||
("20230903_connections_to_subscribe", m20230903_connections_to_subscribe, Just down_m20230903_connections_to_subscribe),
|
||||
("20230914_member_probes", m20230914_member_probes, Just down_m20230914_member_probes)
|
||||
]
|
||||
|
||||
-- | The list of migrations in ascending order by date
|
||||
|
||||
Reference in New Issue
Block a user