core: autoincrement database IDs (#7766)

* core: autoincrement database IDs

* migration

* update simplexmq

---------

Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com>
This commit is contained in:
EvgenyandEvgeny @ SimpleX Chat authored and GitHub committed 2026-10-19 12:14:19 +01:00
1 parent 1cbbe82517
commit 634fa5ecff
11 files changed
+143 -75

No files matched your search

+2 -4
View File
@@ -60,7 +60,7 @@ import Simplex.Messaging.Client (ProtocolClientConfig (..))
import Simplex.Messaging.Client.Agent (defaultSMPClientAgentConfig)
import Simplex.Messaging.Protocol (ProtoServerWithAuth (..), ProtocolServer (..), ProtocolType (..))
import Simplex.Messaging.Server (runSMPServerBlocking)
import Simplex.Messaging.Server.Env.STM (ServerConfig (..), ServerStoreCfg (..), StartOptions (..), StorePaths (..), defaultMessageExpiration, defaultIdleQueueInterval, defaultNtfExpiration, defaultInactiveClientExpiration)
import Simplex.Messaging.Server.Env.STM (ServerConfig (..), ServerStoreCfg (..), StartOptions (..), StorePaths (..), defaultMaxClientCmdWait, defaultMessageExpiration, defaultNtfExpiration, defaultInactiveClientExpiration)
import NameResolver (NameRegistry, resolverNamesConfig, withNameResolver)
import Simplex.Messaging.Server.MsgStore.STM (STMMsgStore)
import Simplex.Messaging.Transport
@@ -638,8 +638,6 @@ smpServerCfg p =
{ transports = [(smpTestPort p, transport @TLS, False)],
tbqSize = 4,
msgQueueQuota = 16,
maxJournalMsgCount = 24,
maxJournalStateLines = 4,
queueIdBytes = 24,
msgIdBytes = 24,
serverStoreCfg = SSCMemory Nothing, -- $ Just StorePaths {storeLogFile = "tmp/smp-server-store.log", storeMsgsFile = Just "tmp/smp-server-messages.log"},
@@ -653,7 +651,6 @@ smpServerCfg p =
messageExpiration = Just defaultMessageExpiration,
expireMessagesOnStart = False,
expireMessagesOnSend = False,
idleQueueInterval = defaultIdleQueueInterval,
notificationExpiration = defaultNtfExpiration,
inactiveClientExpiration = Just defaultInactiveClientExpiration,
smpCredentials =
@@ -680,6 +677,7 @@ smpServerCfg p =
allowSMPProxy = True,
serverClientConcurrency = 16,
serverResolverConcurrency = 1000,
maxClientCmdWait = defaultMaxClientCmdWait,
namesConfig = Nothing,
information = Nothing,
startOptions = StartOptions {maintenance = False, compactLog = False, logLevel = LogError, skipWarnings = False, confirmMigrations = MCYesUp}
+1 -31
View File
@@ -12644,13 +12644,7 @@ testChannelMessageFile ps =
withNewTestChat ps "dan" danProfile $ \dan ->
withNewTestChat ps "eve" eveProfile $ \eve -> withXFTPServer ps $ do
createChannel1Relay "team" alice bob cath dan eve
-- the roster arrives as a file before this one; Postgres assigns it a new id and does not
-- reuse it on delete (SQLite does), so the received message file is id 2 here, 1 on SQLite.
#if defined(dbPostgres)
let rcvFileId = 2 :: Int
#else
let rcvFileId = 1 :: Int
#endif
-- owner sends file as channel message
alice #> "/f #team ./tests/fixtures/test.jpg"
alice <## "use /fc 1 to cancel sending"
@@ -12696,11 +12690,7 @@ testChannelMessageFileCancel ps =
withNewTestChat ps "dan" danProfile $ \dan ->
withNewTestChat ps "eve" eveProfile $ \eve -> withXFTPServer ps $ do
createChannel1Relay "team" alice bob cath dan eve
#if defined(dbPostgres)
let rcvFileId = 2 :: Int
#else
let rcvFileId = 1 :: Int
#endif
-- owner sends file as channel message
alice #> "/f #team ./tests/fixtures/test.jpg"
alice <## "use /fc 1 to cancel sending"
@@ -12876,11 +12866,7 @@ testChannelOwnerFileTransferAsMember ps =
withNewTestChat ps "dan" danProfile $ \dan ->
withNewTestChat ps "eve" eveProfile $ \eve -> withXFTPServer ps $ do
createChannel1Relay "team" alice bob cath dan eve
#if defined(dbPostgres)
let rcvFileId = 2 :: Int
#else
let rcvFileId = 1 :: Int
#endif
-- owner sends file as member (not as channel)
alice ##> "/_send #1(as_group=off) json [{\"filePath\": \"./tests/fixtures/test.jpg\", \"msgContent\": {\"type\": \"file\", \"text\": \"\"}}]"
alice <# "/f #team ./tests/fixtures/test.jpg"
@@ -13028,11 +13014,7 @@ testChannelFileBadgeProof ps = do
withNewTestChatCfg ps cfg "eve" eveProfile $ \eve -> withXFTPServer ps $ do
createChannel1Relay "team" alice bob cath dan eve
addTestBadge alice =<< issueTestBadge sk futureDate
#if defined(dbPostgres)
let rcvFileId = 2 :: Int
#else
let rcvFileId = 1 :: Int
#endif
alice ##> "/_send #1(as_group=off) json [{\"filePath\": \"./tests/fixtures/test.jpg\", \"msgContent\": {\"type\": \"file\", \"text\": \"\"}}]"
alice <# "/f #team ./tests/fixtures/test.jpg"
alice <## "use /fc 1 to cancel sending"
@@ -13095,11 +13077,7 @@ testChannelOwnerFileCancelAsMember ps =
withNewTestChat ps "dan" danProfile $ \dan ->
withNewTestChat ps "eve" eveProfile $ \eve -> withXFTPServer ps $ do
createChannel1Relay "team" alice bob cath dan eve
#if defined(dbPostgres)
let rcvFileId = 2 :: Int
#else
let rcvFileId = 1 :: Int
#endif
-- owner sends file as member (not as channel)
alice ##> "/_send #1(as_group=off) json [{\"filePath\": \"./tests/fixtures/test.jpg\", \"msgContent\": {\"type\": \"file\", \"text\": \"\"}}]"
alice <# "/f #team ./tests/fixtures/test.jpg"
@@ -13475,17 +13453,9 @@ testChannelSignedFile ps =
xftpCLI ["rand", testfile, "1mb"] `shouldReturn` ["File created: " <> testfile]
createChannel1Relay "team" alice bob cath dan eve
promoteChannelMember "team" alice bob cath [dan, eve]
-- roster serves arrive as files that Postgres deletes without reusing the id (SQLite reuses
-- it), so ids run higher here. cath's send and the subscribers' (dan, eve) receive both
-- follow only their join roster (id 2). The relay (bob) also received the roster re-served
-- on cath's promotion, so its file is id 3. The owner (alice) has no roster file, so id 1.
#if defined(dbPostgres)
-- roster files are deleted after the transfer, so ids run higher: cath, dan and eve use id 2, the relay (bob) id 3, the owner (alice) id 1.
let fileId = 2 :: Int
relayFileId = 3 :: Int
#else
let fileId = 1 :: Int
relayFileId = 1 :: Int
#endif
-- cath's first (signed) message introduces her to dan/eve
cath ##> "/_send #1 sign=on text hi"
-27
View File
@@ -2379,11 +2379,7 @@ testPlanAddressContactViaAddress =
bob @@@ [("@alice", "")]
-- GUI api
#if defined(dbPostgres)
bob ##> "/_connect contact 1 4"
#else
bob ##> "/_connect contact 1 2"
#endif
connecting alice bob
where
connecting alice bob = do
@@ -2441,11 +2437,7 @@ testPlanAddressContactViaShortAddress =
bob @@@ [("@alice", "")]
-- GUI api
#if defined(dbPostgres)
bob ##> "/_connect contact 1 4"
#else
bob ##> "/_connect contact 1 2"
#endif
connecting alice bob
where
connecting alice bob = do
@@ -3077,14 +3069,8 @@ testChangePCCUser = testChat2 aliceProfile bobProfile $
alice ##> "/user alisa"
showActiveUser alice "alisa"
-- Change connection back to other user
#if defined(dbPostgres)
alice ##> "/_set conn user :2 3"
alice <## "connection 2 changed from user alisa to user alisa2, new link:"
#else
-- connection ID does not change in SQLite because table has no auto-increment
alice ##> "/_set conn user :1 3"
alice <## "connection 1 changed from user alisa to user alisa2, new link:"
#endif
alice <## ""
_shortInv <- getTermLine alice
alice <## ""
@@ -3126,14 +3112,8 @@ testChangePCCUserFromIncognito = testChat2 aliceProfile bobProfile $
alice ##> "/user alisa"
showActiveUser alice "alisa"
-- Change connection back to initial user
#if defined(dbPostgres)
alice ##> "/_set conn user :2 1"
alice <## "connection 2 changed from user alisa to user alice, new link:"
#else
-- connection ID does not change in SQLite because table has no auto-increment
alice ##> "/_set conn user :1 1"
alice <## "connection 1 changed from user alisa to user alice, new link:"
#endif
alice <## ""
_shortInv <- getTermLine alice
alice <## ""
@@ -3171,16 +3151,9 @@ testChangePCCUserAndThenIncognito = testChat2 aliceProfile bobProfile $
alice ##> "/user alisa"
showActiveUser alice "alisa"
-- Change connection to incognito and make sure it's attached to the newly created user profile
#if defined(dbPostgres)
alice ##> "/_set incognito :2 on"
_ <- getTermLine alice
alice <## "connection 2 changed to incognito"
#else
-- connection ID does not change in SQLite because table has no auto-increment
alice ##> "/_set incognito :1 on"
_ <- getTermLine alice
alice <## "connection 1 changed to incognito"
#endif
bob ##> ("/connect " <> inv)
bob <## "confirmation sent!"
alisaIncognito <- getTermLine alice
+2 -1
View File
@@ -146,7 +146,8 @@ skipComparisonForDownMigrations =
-- appends; CREATE INDEX appends).
"20260529_delivery_job_senders",
-- group_domain is removed
"20260603_simplex_name"
"20260603_simplex_name",
"20261018_autoincrement_ids"
]
getSchema :: FilePath -> FilePath -> IO String