diff --git a/src/Simplex/Messaging/Agent/Store/SQLite/Migrations.hs b/src/Simplex/Messaging/Agent/Store/SQLite/Migrations.hs index f41a34291..341869b85 100644 --- a/src/Simplex/Messaging/Agent/Store/SQLite/Migrations.hs +++ b/src/Simplex/Messaging/Agent/Store/SQLite/Migrations.hs @@ -128,12 +128,9 @@ run st = \case where runUp Migration {name, up, down} = withTransaction' st $ \db -> do when (name == "m20220811_onion_hosts") $ updateServers db - insert db >> execSQL db up' + insert db >> execSQL db up where insert db = DB.execute db "INSERT INTO migrations (name, down, ts) VALUES (?,?,?)" . (name,down,) =<< getCurrentTime - up' - | dbNew st && name == "m20230110_users" = fromQuery new_m20230110_users - | otherwise = up updateServers db = forM_ (M.assocs extraSMPServerHosts) $ \(h, h') -> let hs = decodeLatin1 . strEncode $ ([h, h'] :: NonEmpty TransportHost) in DB.execute db "UPDATE servers SET host = ? WHERE host = ?" (hs, decodeLatin1 $ strEncode h) diff --git a/src/Simplex/Messaging/Agent/Store/SQLite/Migrations/M20230110_users.hs b/src/Simplex/Messaging/Agent/Store/SQLite/Migrations/M20230110_users.hs index 49e6589b9..73758cdeb 100644 --- a/src/Simplex/Messaging/Agent/Store/SQLite/Migrations/M20230110_users.hs +++ b/src/Simplex/Messaging/Agent/Store/SQLite/Migrations/M20230110_users.hs @@ -27,24 +27,3 @@ UPDATE connections SET user_id = 1; PRAGMA ignore_check_constraints=OFF; |] - --- This is executed in the new database --- It does not create new user record -new_m20230110_users :: Query -new_m20230110_users = - [sql| -PRAGMA ignore_check_constraints=ON; - -CREATE TABLE users ( - user_id INTEGER PRIMARY KEY AUTOINCREMENT -); - -ALTER TABLE connections ADD COLUMN user_id INTEGER CHECK (user_id NOT NULL) -REFERENCES users ON DELETE CASCADE; - -CREATE INDEX idx_connections_user ON connections(user_id); - -CREATE INDEX idx_commands_conn_id ON commands(conn_id); - -PRAGMA ignore_check_constraints=OFF; -|] diff --git a/tests/AgentTests/FunctionalAPITests.hs b/tests/AgentTests/FunctionalAPITests.hs index 9793a8220..7a016688a 100644 --- a/tests/AgentTests/FunctionalAPITests.hs +++ b/tests/AgentTests/FunctionalAPITests.hs @@ -36,7 +36,6 @@ import AgentTests.ConnectionRequestTests (connReqData, queueAddr, testE2ERatchet import Control.Concurrent (killThread, threadDelay) import Control.Monad import Control.Monad.Except -import Control.Monad.Reader import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.Either (isRight) @@ -47,15 +46,13 @@ import qualified Data.Set as S import Data.Time.Clock (diffUTCTime, getCurrentTime) import Data.Time.Clock.System (SystemTime (..), getSystemTime) import Data.Type.Equality -import qualified Database.SQLite.Simple as SQL import SMPAgentClient import SMPClient (cfg, testPort, testPort2, testStoreLogFile2, withSmpServer, withSmpServerConfigOn, withSmpServerOn, withSmpServerStoreLogOn, withSmpServerStoreMsgLogOn) import Simplex.Messaging.Agent import Simplex.Messaging.Agent.Client (ProtocolTestFailure (..), ProtocolTestStep (..)) import Simplex.Messaging.Agent.Env.SQLite (AgentConfig (..), InitialAgentServers (..), createAgentStore) import Simplex.Messaging.Agent.Protocol as Agent -import Simplex.Messaging.Agent.Store.SQLite (MigrationConfirmation (..), SQLiteStore (dbNew)) -import Simplex.Messaging.Agent.Store.SQLite.Common (withTransaction') +import Simplex.Messaging.Agent.Store.SQLite (MigrationConfirmation (..)) import Simplex.Messaging.Client (NetworkConfig (..), ProtocolClientConfig (..), TransportSessionMode (TSMEntity, TSMUser), defaultClientConfig) import qualified Simplex.Messaging.Crypto as C import Simplex.Messaging.Encoding.String @@ -2109,9 +2106,7 @@ testTwoUsers = withAgentClients2 $ \a b -> do getSMPAgentClient' :: AgentConfig -> InitialAgentServers -> FilePath -> IO AgentClient getSMPAgentClient' cfg' initServers dbPath = do Right st <- liftIO $ createAgentStore dbPath "" False MCError - c <- getSMPAgentClient cfg' initServers st False - when (dbNew st) $ withTransaction' st (`SQL.execute_` "INSERT INTO users (user_id) VALUES (1)") - pure c + getSMPAgentClient cfg' initServers st False testServerMultipleIdentities :: HasCallStack => IO () testServerMultipleIdentities = diff --git a/tests/AgentTests/SQLiteTests.hs b/tests/AgentTests/SQLiteTests.hs index 98fb47b80..7dbaf3030 100644 --- a/tests/AgentTests/SQLiteTests.hs +++ b/tests/AgentTests/SQLiteTests.hs @@ -34,7 +34,6 @@ import Simplex.Messaging.Agent.Client () import Simplex.Messaging.Agent.Protocol import Simplex.Messaging.Agent.Store import Simplex.Messaging.Agent.Store.SQLite -import Simplex.Messaging.Agent.Store.SQLite.Common (withTransaction') import qualified Simplex.Messaging.Agent.Store.SQLite.DB as DB import qualified Simplex.Messaging.Agent.Store.SQLite.Migrations as Migrations import qualified Simplex.Messaging.Crypto as C @@ -70,7 +69,6 @@ createEncryptedStore key keepKey = do -- IO operations on multiple similarly named files; error seems to be environment specific r <- randomIO :: IO Word32 Right st <- createSQLiteStore (testDB <> show r) key keepKey Migrations.app MCError - withTransaction' st (`SQL.execute_` "INSERT INTO users (user_id) VALUES (1);") pure st removeStore :: SQLiteStore -> IO () diff --git a/tests/AgentTests/SchemaDump.hs b/tests/AgentTests/SchemaDump.hs index c32b69f10..3c8246366 100644 --- a/tests/AgentTests/SchemaDump.hs +++ b/tests/AgentTests/SchemaDump.hs @@ -7,10 +7,7 @@ import Control.DeepSeq import Control.Monad (unless, void) import Data.List (dropWhileEnd) import Data.Maybe (fromJust, isJust) -import Database.SQLite.Simple (Only (..)) -import qualified Database.SQLite.Simple as SQL import Simplex.Messaging.Agent.Store.SQLite -import Simplex.Messaging.Agent.Store.SQLite.Common (withTransaction') 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) @@ -31,8 +28,6 @@ schemaDumpTest :: Spec schemaDumpTest = do it "verify and overwrite schema dump" testVerifySchemaDump it "verify schema down migrations" testSchemaMigrations - it "should NOT create user record for new database" testUsersMigrationNew - it "should create user record for old database" testUsersMigrationOld testVerifySchemaDump :: IO () testVerifySchemaDump = do @@ -66,25 +61,6 @@ testSchemaMigrations = do schema''' <- getSchema testDB testSchema schema''' `shouldBe` schema' -testUsersMigrationNew :: IO () -testUsersMigrationNew = do - Right st <- createSQLiteStore testDB "" False Migrations.app MCError - withTransaction' st (`SQL.query_` "SELECT user_id FROM users;") - `shouldReturn` ([] :: [Only Int]) - closeSQLiteStore st - -testUsersMigrationOld :: IO () -testUsersMigrationOld = do - let beforeUsers = takeWhile (("m20230110_users" /=) . name) Migrations.app - Right st <- createSQLiteStore testDB "" False beforeUsers MCError - withTransaction' st (`SQL.query_` "SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'users';") - `shouldReturn` ([] :: [Only String]) - closeSQLiteStore st - Right st' <- createSQLiteStore testDB "" False Migrations.app MCYesUp - withTransaction' st' (`SQL.query_` "SELECT user_id FROM users;") - `shouldReturn` ([Only (1 :: Int)]) - closeSQLiteStore st' - skipComparisonForDownMigrations :: [String] skipComparisonForDownMigrations = [ -- on down migration idx_messages_internal_snd_id_ts index moves down to the end of the file diff --git a/tests/SMPAgentClient.hs b/tests/SMPAgentClient.hs index dc5cc2a2f..c39f6fa43 100644 --- a/tests/SMPAgentClient.hs +++ b/tests/SMPAgentClient.hs @@ -9,14 +9,12 @@ module SMPAgentClient where -import Control.Monad import Control.Monad.IO.Unlift import Crypto.Random import qualified Data.ByteString.Char8 as B import Data.List.NonEmpty (NonEmpty) import Data.Map.Strict (Map) import qualified Data.Map.Strict as M -import qualified Database.SQLite.Simple as SQL import Network.Socket (ServiceName) import NtfClient (ntfTestPort) import SMPClient @@ -32,8 +30,7 @@ import Simplex.Messaging.Agent.Env.SQLite import Simplex.Messaging.Agent.Protocol import Simplex.Messaging.Agent.RetryInterval import Simplex.Messaging.Agent.Server (runSMPAgentBlocking) -import Simplex.Messaging.Agent.Store.SQLite (MigrationConfirmation (..), SQLiteStore (dbNew)) -import Simplex.Messaging.Agent.Store.SQLite.Common (withTransaction') +import Simplex.Messaging.Agent.Store.SQLite (MigrationConfirmation (..)) import Simplex.Messaging.Client (ProtocolClientConfig (..), chooseTransportHost, defaultClientConfig, defaultNetworkConfig) import Simplex.Messaging.Parsers (parseAll) import Simplex.Messaging.Protocol (ProtoServerWithAuth) @@ -217,7 +214,6 @@ withSmpAgentThreadOn_ t (port', smpPort', db') afterProcess = in serverBracket ( \started -> do Right st <- liftIO $ createAgentStore db' "" False MCError - when (dbNew st) . liftIO $ withTransaction' st (`SQL.execute_` "INSERT INTO users (user_id) VALUES (1)") runSMPAgentBlocking t cfg' initServers' st started ) afterProcess