mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-15 17:35:45 +00:00
refactor(wakunode2): Split wankunode2 SQL migrations setup to its own file
This commit is contained in:
parent
e16747137e
commit
10c237dc5f
@ -1,46 +1,5 @@
|
||||
{.push raises: [Defect].}
|
||||
|
||||
## Collection of utilities commonly used
|
||||
## during the setup phase of a Waku v2 node
|
||||
import stew/results
|
||||
|
||||
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
|
||||
info "running migration ...", migrationPath=migrationPath
|
||||
let migrationResult = sqliteDatabase.migrate(migrationPath)
|
||||
if migrationResult.isErr:
|
||||
warn "migration failed", error=migrationResult.error
|
||||
else:
|
||||
info "migration is done"
|
||||
type SetupResult*[T] = Result[T, string]
|
||||
|
@ -794,6 +794,7 @@ when isMainModule:
|
||||
./wakunode2_setup_rest,
|
||||
./wakunode2_setup_metrics,
|
||||
./wakunode2_setup_rpc,
|
||||
./wakunode2_setup_sql_migrations,
|
||||
./storage/message/waku_message_store,
|
||||
./storage/peer/waku_peer_storage
|
||||
|
||||
|
29
waku/v2/node/wakunode2_setup_sql_migrations.nim
Normal file
29
waku/v2/node/wakunode2_setup_sql_migrations.nim
Normal file
@ -0,0 +1,29 @@
|
||||
{.push raises: [Defect].}
|
||||
|
||||
import
|
||||
chronicles,
|
||||
./storage/sqlite,
|
||||
./storage/migration/migration_types,
|
||||
./config,
|
||||
./wakunode2
|
||||
|
||||
logScope:
|
||||
topics = "wakunode.setup.migrations"
|
||||
|
||||
|
||||
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
|
||||
|
||||
info "running migration ...", migrationPath=migrationPath
|
||||
let migrationResult = sqliteDatabase.migrate(migrationPath)
|
||||
if migrationResult.isErr:
|
||||
warn "migration failed", error=migrationResult.error
|
||||
else:
|
||||
info "migration is done"
|
Loading…
x
Reference in New Issue
Block a user