Skip to content

Commit 2ce2453

Browse files
authored
fix: avoid double db migration for sqlite (#3244)
1 parent 122e0f3 commit 2ce2453

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

waku/factory/node_factory.nim

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ import
3535
../node/peer_manager/peer_store/migrations as peer_store_sqlite_migrations,
3636
../waku_lightpush/common,
3737
../common/utils/parse_size_units,
38-
../common/rate_limit/setting
38+
../common/rate_limit/setting,
39+
../common/databases/dburl
3940

4041
## Peer persistence
4142

@@ -267,8 +268,27 @@ proc setupProtocols(
267268
## then the legacy will be in charge of performing the archiving.
268269
## Regarding storage, the only diff between the current/future archive driver and the legacy
269270
## one, is that the legacy stores an extra field: the id (message digest.)
271+
272+
## TODO: remove this "migrate" variable once legacy store is removed
273+
## It is now necessary because sqlite's legacy store has an extra field: storedAt
274+
## This breaks compatibility between store's and legacy store's schemas in sqlite
275+
## So for now, we need to make sure that when legacy store is enabled and we use sqlite
276+
## that we migrate our db according to legacy store's schema to have the extra field
277+
278+
let engineRes = dburl.getDbEngine(conf.storeMessageDbUrl)
279+
if engineRes.isErr():
280+
return err("error getting db engine in setupProtocols: " & engineRes.error)
281+
282+
let engine = engineRes.get()
283+
284+
let migrate =
285+
if engine == "sqlite" and conf.legacyStore:
286+
false
287+
else:
288+
conf.storeMessageDbMigration
289+
270290
let archiveDriverRes = waitFor driver.ArchiveDriver.new(
271-
conf.storeMessageDbUrl, conf.storeMessageDbVacuum, conf.storeMessageDbMigration,
291+
conf.storeMessageDbUrl, conf.storeMessageDbVacuum, migrate,
272292
conf.storeMaxNumDbConnections, onFatalErrorAction,
273293
)
274294
if archiveDriverRes.isErr():

0 commit comments

Comments
 (0)