diff --git a/src/Simplex/Chat/Migrations/M20230318_file_description.hs b/src/Simplex/Chat/Migrations/M20230318_file_description.hs index 76d4ec979b..39f56b2a48 100644 --- a/src/Simplex/Chat/Migrations/M20230318_file_description.hs +++ b/src/Simplex/Chat/Migrations/M20230318_file_description.hs @@ -37,3 +37,20 @@ CREATE INDEX idx_rcv_files_file_descr_id ON rcv_files(file_descr_id); ALTER TABLE rcv_files ADD COLUMN agent_rcv_file_id BLOB NULL; |] + +down_m20230318_file_description :: Query +down_m20230318_file_description = + [sql| +ALTER TABLE rcv_files DROP COLUMN agent_rcv_file_id; + +DROP INDEX idx_rcv_files_file_descr_id; +ALTER TABLE rcv_files DROP COLUMN file_descr_id; + +DROP INDEX idx_snd_files_file_descr_id; +ALTER TABLE snd_files DROP COLUMN file_descr_id; + +ALTER TABLE files DROP COLUMN private_snd_file_descr; +ALTER TABLE files DROP COLUMN agent_snd_file_id; + +DROP TABLE xftp_file_descriptions; +|] diff --git a/src/Simplex/Chat/Migrations/M20230321_agent_file_deleted.hs b/src/Simplex/Chat/Migrations/M20230321_agent_file_deleted.hs index 15a08febfe..97c213ea48 100644 --- a/src/Simplex/Chat/Migrations/M20230321_agent_file_deleted.hs +++ b/src/Simplex/Chat/Migrations/M20230321_agent_file_deleted.hs @@ -18,3 +18,11 @@ UPDATE rcv_files SET agent_rcv_file_deleted = 0; PRAGMA ignore_check_constraints=OFF; |] + +down_m20230321_agent_file_deleted :: Query +down_m20230321_agent_file_deleted = + [sql| +ALTER TABLE rcv_files DROP COLUMN agent_rcv_file_deleted; + +ALTER TABLE files DROP COLUMN agent_snd_file_deleted; +|] diff --git a/src/Simplex/Chat/Store.hs b/src/Simplex/Chat/Store.hs index aa3ff98333..1d45e2fe92 100644 --- a/src/Simplex/Chat/Store.hs +++ b/src/Simplex/Chat/Store.hs @@ -431,8 +431,8 @@ schemaMigrations = ("20230206_item_deleted_by_group_member_id", m20230206_item_deleted_by_group_member_id, Nothing), ("20230303_group_link_role", m20230303_group_link_role, Nothing), ("20230317_hidden_profiles", m20230317_hidden_profiles, Just down_m20230317_hidden_profiles), - ("20230318_file_description", m20230318_file_description, Nothing), - ("20230321_agent_file_deleted", m20230321_agent_file_deleted, Nothing) + ("20230318_file_description", m20230318_file_description, Just down_m20230318_file_description), + ("20230321_agent_file_deleted", m20230321_agent_file_deleted, Just down_m20230321_agent_file_deleted) ] -- | The list of migrations in ascending order by date diff --git a/tests/SchemaDump.hs b/tests/SchemaDump.hs index 96197f1295..5a6b53156d 100644 --- a/tests/SchemaDump.hs +++ b/tests/SchemaDump.hs @@ -13,7 +13,7 @@ import qualified Simplex.Chat.Store as Store import Simplex.Messaging.Agent.Store.SQLite (MigrationConfirmation (..), closeSQLiteStore, createSQLiteStore, withConnection) import Simplex.Messaging.Agent.Store.SQLite.Migrations (Migration (..), MigrationsToRun (..), toDownMigration) import qualified Simplex.Messaging.Agent.Store.SQLite.Migrations as Migrations -import Simplex.Messaging.Util (ifM) +import Simplex.Messaging.Util (ifM, whenM) import System.Directory (doesFileExist, removeFile) import System.Process (readCreateProcess, shell) import Test.Hspec @@ -47,7 +47,7 @@ testSchemaMigrations = withTmpFiles $ do mapM_ (testDownMigration st) $ drop (length noDownMigrations) Store.migrations closeSQLiteStore st removeFile testDB - removeFile testSchema + whenM (doesFileExist testSchema) $ removeFile testSchema where testDownMigration st m = do putStrLn $ "down migration " <> name m