Skip to content

Commit

Permalink
fix: avoid double db migration for sqlite (#3244)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer authored Jan 20, 2025
1 parent 122e0f3 commit 2ce2453
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions waku/factory/node_factory.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import
../node/peer_manager/peer_store/migrations as peer_store_sqlite_migrations,
../waku_lightpush/common,
../common/utils/parse_size_units,
../common/rate_limit/setting
../common/rate_limit/setting,
../common/databases/dburl

## Peer persistence

Expand Down Expand Up @@ -267,8 +268,27 @@ proc setupProtocols(
## then the legacy will be in charge of performing the archiving.
## Regarding storage, the only diff between the current/future archive driver and the legacy
## one, is that the legacy stores an extra field: the id (message digest.)

## TODO: remove this "migrate" variable once legacy store is removed
## It is now necessary because sqlite's legacy store has an extra field: storedAt
## This breaks compatibility between store's and legacy store's schemas in sqlite
## So for now, we need to make sure that when legacy store is enabled and we use sqlite
## that we migrate our db according to legacy store's schema to have the extra field

let engineRes = dburl.getDbEngine(conf.storeMessageDbUrl)
if engineRes.isErr():
return err("error getting db engine in setupProtocols: " & engineRes.error)

let engine = engineRes.get()

let migrate =
if engine == "sqlite" and conf.legacyStore:
false
else:
conf.storeMessageDbMigration

let archiveDriverRes = waitFor driver.ArchiveDriver.new(
conf.storeMessageDbUrl, conf.storeMessageDbVacuum, conf.storeMessageDbMigration,
conf.storeMessageDbUrl, conf.storeMessageDbVacuum, migrate,
conf.storeMaxNumDbConnections, onFatalErrorAction,
)
if archiveDriverRes.isErr():
Expand Down

0 comments on commit 2ce2453

Please sign in to comment.