2021-07-22 09:46:54 +00:00
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
|
|
|
## Collection of utilities commonly used
|
|
|
|
## during the setup phase of a Waku v2 node
|
|
|
|
|
|
|
|
import
|
|
|
|
std/tables,
|
|
|
|
chronos,
|
|
|
|
chronicles,
|
|
|
|
metrics,
|
|
|
|
metrics/chronos_httpserver,
|
|
|
|
stew/results,
|
|
|
|
stew/shims/net,
|
|
|
|
./storage/sqlite,
|
|
|
|
./storage/migration/migration_types,
|
|
|
|
./config,
|
|
|
|
./wakunode2
|
|
|
|
|
|
|
|
logScope:
|
|
|
|
topics = "wakunode.setup"
|
|
|
|
|
|
|
|
type
|
|
|
|
SetupResult*[T] = Result[T, string]
|
|
|
|
|
|
|
|
##########################
|
|
|
|
# Setup helper functions #
|
|
|
|
##########################
|
|
|
|
|
|
|
|
proc runMigrations*(sqliteDatabase: SqliteDatabase, conf: WakuNodeConf) =
|
|
|
|
# Run migration scripts on persistent storage
|
|
|
|
|
|
|
|
var migrationPath: string
|
|
|
|
if conf.persistPeers and conf.persistMessages:
|
|
|
|
migrationPath = migration_types.ALL_STORE_MIGRATION_PATH
|
|
|
|
elif conf.persistPeers:
|
|
|
|
migrationPath = migration_types.PEER_STORE_MIGRATION_PATH
|
|
|
|
elif conf.persistMessages:
|
|
|
|
migrationPath = migration_types.MESSAGE_STORE_MIGRATION_PATH
|
|
|
|
|
|
|
|
# run migration
|
2021-12-07 12:06:59 +00:00
|
|
|
info "running migration ...", migrationPath=migrationPath
|
2021-07-22 09:46:54 +00:00
|
|
|
let migrationResult = sqliteDatabase.migrate(migrationPath)
|
|
|
|
if migrationResult.isErr:
|
2021-12-07 12:06:59 +00:00
|
|
|
warn "migration failed", error=migrationResult.error
|
2021-07-22 09:46:54 +00:00
|
|
|
else:
|
|
|
|
info "migration is done"
|