mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-11 04:07:10 +00:00
Merge branch 'master' into chat-relays
This commit is contained in:
@@ -20,7 +20,8 @@ import Simplex.Chat.Store.Postgres.Migrations.M20250813_delivery_tasks
|
||||
import Simplex.Chat.Store.Postgres.Migrations.M20250919_group_summary
|
||||
import Simplex.Chat.Store.Postgres.Migrations.M20250922_remove_unused_connections
|
||||
import Simplex.Chat.Store.Postgres.Migrations.M20251007_connections_sync
|
||||
import Simplex.Chat.Store.Postgres.Migrations.M20251016_chat_relays
|
||||
import Simplex.Chat.Store.Postgres.Migrations.M20251017_chat_tags_cascade
|
||||
import Simplex.Chat.Store.Postgres.Migrations.M20251018_chat_relays
|
||||
import Simplex.Messaging.Agent.Store.Shared (Migration (..))
|
||||
|
||||
schemaMigrations :: [(String, Text, Maybe Text)]
|
||||
@@ -41,7 +42,8 @@ schemaMigrations =
|
||||
("20250919_group_summary", m20250919_group_summary, Just down_m20250919_group_summary),
|
||||
("20250922_remove_unused_connections", m20250922_remove_unused_connections, Just down_m20250922_remove_unused_connections),
|
||||
("20251007_connections_sync", m20251007_connections_sync, Just down_m20251007_connections_sync),
|
||||
("20251016_chat_relays", m20251016_chat_relays, Just down_m20251016_chat_relays)
|
||||
("20251017_chat_tags_cascade", m20251017_chat_tags_cascade, Just down_m20251017_chat_tags_cascade),
|
||||
("20251018_chat_relays", m20251018_chat_relays, Just down_m20251018_chat_relays)
|
||||
]
|
||||
|
||||
-- | The list of migrations in ascending order by date
|
||||
|
||||
@@ -16,7 +16,7 @@ CREATE TABLE connections_sync(
|
||||
last_sync_ts TIMESTAMPTZ
|
||||
);
|
||||
|
||||
INSERT INTO connections_sync (connections_sync_id, should_sync, last_sync_ts) VALUES (1,0,NULL);
|
||||
INSERT INTO connections_sync (connections_sync_id, should_sync, last_sync_ts) VALUES (1, 1, NULL);
|
||||
|]
|
||||
|
||||
down_m20251007_connections_sync :: Text
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Simplex.Chat.Store.Postgres.Migrations.M20251017_chat_tags_cascade where
|
||||
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import Text.RawString.QQ (r)
|
||||
|
||||
m20251017_chat_tags_cascade :: Text
|
||||
m20251017_chat_tags_cascade =
|
||||
T.pack
|
||||
[r|
|
||||
ALTER TABLE chat_tags DROP CONSTRAINT chat_tags_user_id_fkey;
|
||||
|
||||
ALTER TABLE chat_tags
|
||||
ADD CONSTRAINT chat_tags_user_id_fkey
|
||||
FOREIGN KEY (user_id)
|
||||
REFERENCES users(user_id)
|
||||
ON DELETE CASCADE;
|
||||
|]
|
||||
|
||||
down_m20251017_chat_tags_cascade :: Text
|
||||
down_m20251017_chat_tags_cascade =
|
||||
T.pack
|
||||
[r|
|
||||
ALTER TABLE chat_tags DROP CONSTRAINT chat_tags_user_id_fkey;
|
||||
|
||||
ALTER TABLE chat_tags
|
||||
ADD CONSTRAINT chat_tags_user_id_fkey
|
||||
FOREIGN KEY (user_id)
|
||||
REFERENCES users(user_id);
|
||||
|]
|
||||
+5
-5
@@ -1,13 +1,13 @@
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Simplex.Chat.Store.Postgres.Migrations.M20251016_chat_relays where
|
||||
module Simplex.Chat.Store.Postgres.Migrations.M20251018_chat_relays where
|
||||
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import Text.RawString.QQ (r)
|
||||
|
||||
m20251016_chat_relays :: Text
|
||||
m20251016_chat_relays =
|
||||
m20251018_chat_relays :: Text
|
||||
m20251018_chat_relays =
|
||||
T.pack
|
||||
[r|
|
||||
CREATE TABLE chat_relays(
|
||||
@@ -32,8 +32,8 @@ ALTER TABLE users ADD COLUMN is_user_chat_relay SMALLINT NOT NULL DEFAULT 0;
|
||||
ALTER TABLE group_members ADD COLUMN is_chat_relay SMALLINT NOT NULL DEFAULT 0;
|
||||
|]
|
||||
|
||||
down_m20251016_chat_relays :: Text
|
||||
down_m20251016_chat_relays =
|
||||
down_m20251018_chat_relays :: Text
|
||||
down_m20251018_chat_relays =
|
||||
T.pack
|
||||
[r|
|
||||
ALTER TABLE group_members DROP COLUMN is_chat_relay;
|
||||
@@ -2479,7 +2479,7 @@ ALTER TABLE ONLY test_chat_schema.chat_tags_chats
|
||||
|
||||
|
||||
ALTER TABLE ONLY test_chat_schema.chat_tags
|
||||
ADD CONSTRAINT chat_tags_user_id_fkey FOREIGN KEY (user_id) REFERENCES test_chat_schema.users(user_id);
|
||||
ADD CONSTRAINT chat_tags_user_id_fkey FOREIGN KEY (user_id) REFERENCES test_chat_schema.users(user_id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -143,7 +143,8 @@ import Simplex.Chat.Store.SQLite.Migrations.M20250813_delivery_tasks
|
||||
import Simplex.Chat.Store.SQLite.Migrations.M20250919_group_summary
|
||||
import Simplex.Chat.Store.SQLite.Migrations.M20250922_remove_unused_connections
|
||||
import Simplex.Chat.Store.SQLite.Migrations.M20251007_connections_sync
|
||||
import Simplex.Chat.Store.SQLite.Migrations.M20251016_chat_relays
|
||||
import Simplex.Chat.Store.SQLite.Migrations.M20251017_chat_tags_cascade
|
||||
import Simplex.Chat.Store.SQLite.Migrations.M20251018_chat_relays
|
||||
import Simplex.Messaging.Agent.Store.Shared (Migration (..))
|
||||
|
||||
schemaMigrations :: [(String, Query, Maybe Query)]
|
||||
@@ -287,7 +288,8 @@ schemaMigrations =
|
||||
("20250919_group_summary", m20250919_group_summary, Just down_m20250919_group_summary),
|
||||
("20250922_remove_unused_connections", m20250922_remove_unused_connections, Just down_m20250922_remove_unused_connections),
|
||||
("20251007_connections_sync", m20251007_connections_sync, Just down_m20251007_connections_sync),
|
||||
("20251016_chat_relays", m20251016_chat_relays, Just down_m20251016_chat_relays)
|
||||
("20251017_chat_tags_cascade", m20251017_chat_tags_cascade, Just down_m20251017_chat_tags_cascade),
|
||||
("20251018_chat_relays", m20251018_chat_relays, Just down_m20251018_chat_relays)
|
||||
]
|
||||
|
||||
-- | The list of migrations in ascending order by date
|
||||
|
||||
@@ -15,7 +15,7 @@ CREATE TABLE connections_sync(
|
||||
last_sync_ts TEXT
|
||||
);
|
||||
|
||||
INSERT INTO connections_sync (connections_sync_id, should_sync, last_sync_ts) VALUES (1,0,NULL);
|
||||
INSERT INTO connections_sync (connections_sync_id, should_sync, last_sync_ts) VALUES (1, 1, NULL);
|
||||
|]
|
||||
|
||||
down_m20251007_connections_sync :: Query
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Simplex.Chat.Store.SQLite.Migrations.M20251017_chat_tags_cascade where
|
||||
|
||||
import Database.SQLite.Simple (Query)
|
||||
import Database.SQLite.Simple.QQ (sql)
|
||||
|
||||
m20251017_chat_tags_cascade :: Query
|
||||
m20251017_chat_tags_cascade =
|
||||
[sql|
|
||||
PRAGMA writable_schema=1;
|
||||
|
||||
UPDATE sqlite_master
|
||||
SET sql = replace(sql, 'user_id INTEGER REFERENCES users', 'user_id INTEGER REFERENCES users ON DELETE CASCADE')
|
||||
WHERE name = 'chat_tags' AND type = 'table';
|
||||
|
||||
PRAGMA writable_schema=0;
|
||||
|]
|
||||
|
||||
down_m20251017_chat_tags_cascade :: Query
|
||||
down_m20251017_chat_tags_cascade =
|
||||
[sql|
|
||||
PRAGMA writable_schema=1;
|
||||
|
||||
UPDATE sqlite_master
|
||||
SET sql = replace(sql, 'user_id INTEGER REFERENCES users ON DELETE CASCADE', 'user_id INTEGER REFERENCES users')
|
||||
WHERE name = 'chat_tags' AND type = 'table';
|
||||
|
||||
PRAGMA writable_schema=0;
|
||||
|]
|
||||
+5
-5
@@ -1,12 +1,12 @@
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Simplex.Chat.Store.SQLite.Migrations.M20251016_chat_relays where
|
||||
module Simplex.Chat.Store.SQLite.Migrations.M20251018_chat_relays where
|
||||
|
||||
import Database.SQLite.Simple (Query)
|
||||
import Database.SQLite.Simple.QQ (sql)
|
||||
|
||||
m20251016_chat_relays :: Query
|
||||
m20251016_chat_relays =
|
||||
m20251018_chat_relays :: Query
|
||||
m20251018_chat_relays =
|
||||
[sql|
|
||||
CREATE TABLE chat_relays(
|
||||
chat_relay_id INTEGER PRIMARY KEY,
|
||||
@@ -30,8 +30,8 @@ ALTER TABLE users ADD COLUMN is_user_chat_relay INTEGER NOT NULL DEFAULT 0;
|
||||
ALTER TABLE group_members ADD COLUMN is_chat_relay INTEGER NOT NULL DEFAULT 0;
|
||||
|]
|
||||
|
||||
down_m20251016_chat_relays :: Query
|
||||
down_m20251016_chat_relays =
|
||||
down_m20251018_chat_relays :: Query
|
||||
down_m20251018_chat_relays =
|
||||
[sql|
|
||||
ALTER TABLE group_members DROP COLUMN is_chat_relay;
|
||||
|
||||
@@ -3337,6 +3337,16 @@ Query:
|
||||
Plan:
|
||||
SEARCH chat_relays USING INDEX idx_chat_relays_user_id (user_id=?)
|
||||
|
||||
Query:
|
||||
SELECT chat_tag_id, chat_tag_emoji, chat_tag_text
|
||||
FROM chat_tags
|
||||
WHERE user_id = ?
|
||||
ORDER BY tag_order
|
||||
|
||||
Plan:
|
||||
SEARCH chat_tags USING INDEX idx_chat_tags_user_id (user_id=?)
|
||||
USE TEMP B-TREE FOR ORDER BY
|
||||
|
||||
Query:
|
||||
SELECT command_id, connection_id, command_function, command_status
|
||||
FROM commands
|
||||
@@ -4341,6 +4351,20 @@ Query:
|
||||
|
||||
Plan:
|
||||
|
||||
Query:
|
||||
INSERT INTO chat_tags (user_id, chat_tag_emoji, chat_tag_text, tag_order)
|
||||
VALUES (?,?,?, COALESCE((SELECT MAX(tag_order) + 1 FROM chat_tags WHERE user_id = ?), 1))
|
||||
|
||||
Plan:
|
||||
SCALAR SUBQUERY 1
|
||||
SEARCH chat_tags USING INDEX idx_chat_tags_user_id (user_id=?)
|
||||
|
||||
Query:
|
||||
INSERT INTO chat_tags_chats (contact_id, chat_tag_id)
|
||||
VALUES (?,?)
|
||||
|
||||
Plan:
|
||||
|
||||
Query:
|
||||
INSERT INTO commands (connection_id, command_function, command_status, user_id, created_at, updated_at)
|
||||
VALUES (?,?,?,?,?,?)
|
||||
|
||||
@@ -665,7 +665,7 @@ CREATE TABLE operator_usage_conditions(
|
||||
);
|
||||
CREATE TABLE chat_tags(
|
||||
chat_tag_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER REFERENCES users,
|
||||
user_id INTEGER REFERENCES users ON DELETE CASCADE,
|
||||
chat_tag_text TEXT NOT NULL,
|
||||
chat_tag_emoji TEXT,
|
||||
tag_order INTEGER NOT NULL
|
||||
|
||||
Reference in New Issue
Block a user