From 0be7a3117a2b4eb7f13f1ff639188bb3ff826af8 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Fri, 22 Dec 2023 11:09:33 +0400 Subject: [PATCH] unite migrations --- simplex-chat.cabal | 3 +-- .../Migrations/M20231214_item_content_tag.hs | 18 ------------------ ...eliveries.hs => M20231215_group_history.hs} | 14 +++++++++----- src/Simplex/Chat/Store/Migrations.hs | 6 ++---- tests/SchemaDump.hs | 2 +- 5 files changed, 13 insertions(+), 30 deletions(-) delete mode 100644 src/Simplex/Chat/Migrations/M20231214_item_content_tag.hs rename src/Simplex/Chat/Migrations/{M20231215_recreate_msg_deliveries.hs => M20231215_group_history.hs} (91%) diff --git a/simplex-chat.cabal b/simplex-chat.cabal index 6622b33f3..e10dd58d9 100644 --- a/simplex-chat.cabal +++ b/simplex-chat.cabal @@ -127,8 +127,7 @@ library Simplex.Chat.Migrations.M20231114_remote_control Simplex.Chat.Migrations.M20231126_remote_ctrl_address Simplex.Chat.Migrations.M20231207_chat_list_pagination - Simplex.Chat.Migrations.M20231214_item_content_tag - Simplex.Chat.Migrations.M20231215_recreate_msg_deliveries + Simplex.Chat.Migrations.M20231215_group_history Simplex.Chat.Mobile Simplex.Chat.Mobile.File Simplex.Chat.Mobile.Shared diff --git a/src/Simplex/Chat/Migrations/M20231214_item_content_tag.hs b/src/Simplex/Chat/Migrations/M20231214_item_content_tag.hs deleted file mode 100644 index cd4cd136e..000000000 --- a/src/Simplex/Chat/Migrations/M20231214_item_content_tag.hs +++ /dev/null @@ -1,18 +0,0 @@ -{-# LANGUAGE QuasiQuotes #-} - -module Simplex.Chat.Migrations.M20231214_item_content_tag where - -import Database.SQLite.Simple (Query) -import Database.SQLite.Simple.QQ (sql) - -m20231214_item_content_tag :: Query -m20231214_item_content_tag = - [sql| -ALTER TABLE chat_items ADD COLUMN item_content_tag TEXT; -|] - -down_m20231214_item_content_tag :: Query -down_m20231214_item_content_tag = - [sql| -ALTER TABLE chat_items DROP COLUMN item_content_tag; -|] diff --git a/src/Simplex/Chat/Migrations/M20231215_recreate_msg_deliveries.hs b/src/Simplex/Chat/Migrations/M20231215_group_history.hs similarity index 91% rename from src/Simplex/Chat/Migrations/M20231215_recreate_msg_deliveries.hs rename to src/Simplex/Chat/Migrations/M20231215_group_history.hs index 6a5dac98b..f32b492c8 100644 --- a/src/Simplex/Chat/Migrations/M20231215_recreate_msg_deliveries.hs +++ b/src/Simplex/Chat/Migrations/M20231215_group_history.hs @@ -1,13 +1,15 @@ {-# LANGUAGE QuasiQuotes #-} -module Simplex.Chat.Migrations.M20231215_recreate_msg_deliveries where +module Simplex.Chat.Migrations.M20231215_group_history where import Database.SQLite.Simple (Query) import Database.SQLite.Simple.QQ (sql) -m20231215_recreate_msg_deliveries :: Query -m20231215_recreate_msg_deliveries = +m20231215_group_history :: Query +m20231215_group_history = [sql| +ALTER TABLE chat_items ADD COLUMN item_content_tag TEXT; + DROP INDEX msg_delivery_events_msg_delivery_id; DROP TABLE msg_delivery_events; @@ -42,8 +44,8 @@ CREATE INDEX idx_msg_deliveries_agent_msg_id ON "msg_deliveries"(connection_id, |] -- msg_deliveries are not repopulated on down migration, as it may cause constraint violations -down_m20231215_recreate_msg_deliveries :: Query -down_m20231215_recreate_msg_deliveries = +down_m20231215_group_history :: Query +down_m20231215_group_history = [sql| DROP INDEX idx_msg_deliveries_message_id; DROP INDEX idx_msg_deliveries_agent_ack_cmd_id; @@ -76,4 +78,6 @@ CREATE TABLE msg_delivery_events ( UNIQUE (msg_delivery_id, delivery_status) ); CREATE INDEX msg_delivery_events_msg_delivery_id ON msg_delivery_events(msg_delivery_id); + +ALTER TABLE chat_items DROP COLUMN item_content_tag; |] diff --git a/src/Simplex/Chat/Store/Migrations.hs b/src/Simplex/Chat/Store/Migrations.hs index 61fbfe359..32ea2b872 100644 --- a/src/Simplex/Chat/Store/Migrations.hs +++ b/src/Simplex/Chat/Store/Migrations.hs @@ -92,8 +92,7 @@ import Simplex.Chat.Migrations.M20231113_group_forward import Simplex.Chat.Migrations.M20231114_remote_control import Simplex.Chat.Migrations.M20231126_remote_ctrl_address import Simplex.Chat.Migrations.M20231207_chat_list_pagination -import Simplex.Chat.Migrations.M20231214_item_content_tag -import Simplex.Chat.Migrations.M20231215_recreate_msg_deliveries +import Simplex.Chat.Migrations.M20231215_group_history import Simplex.Messaging.Agent.Store.SQLite.Migrations (Migration (..)) schemaMigrations :: [(String, Query, Maybe Query)] @@ -186,8 +185,7 @@ schemaMigrations = ("20231114_remote_control", m20231114_remote_control, Just down_m20231114_remote_control), ("20231126_remote_ctrl_address", m20231126_remote_ctrl_address, Just down_m20231126_remote_ctrl_address), ("20231207_chat_list_pagination", m20231207_chat_list_pagination, Just down_m20231207_chat_list_pagination), - ("20231214_item_content_tag", m20231214_item_content_tag, Just down_m20231214_item_content_tag), - ("20231215_recreate_msg_deliveries", m20231215_recreate_msg_deliveries, Just down_m20231215_recreate_msg_deliveries) + ("20231215_group_history", m20231215_group_history, Just down_m20231215_group_history) ] -- | The list of migrations in ascending order by date diff --git a/tests/SchemaDump.hs b/tests/SchemaDump.hs index 77269a9b3..e0ce6d394 100644 --- a/tests/SchemaDump.hs +++ b/tests/SchemaDump.hs @@ -75,7 +75,7 @@ skipComparisonForDownMigrations = -- on down migration idx_connections_via_contact_uri_hash index moves down to the end of the file "20231019_indexes", -- table and indexes move down to the end of the file - "20231215_recreate_msg_deliveries" + "20231215_group_history" ] getSchema :: FilePath -> FilePath -> IO String