mirror of https://github.com/waku-org/nwaku.git
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].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
## Collection of utilities commonly used
|
import stew/results
|
||||||
## during the setup phase of a Waku v2 node
|
|
||||||
|
|
||||||
import
|
type SetupResult*[T] = Result[T, string]
|
||||||
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"
|
|
||||||
|
|
|
@ -794,6 +794,7 @@ when isMainModule:
|
||||||
./wakunode2_setup_rest,
|
./wakunode2_setup_rest,
|
||||||
./wakunode2_setup_metrics,
|
./wakunode2_setup_metrics,
|
||||||
./wakunode2_setup_rpc,
|
./wakunode2_setup_rpc,
|
||||||
|
./wakunode2_setup_sql_migrations,
|
||||||
./storage/message/waku_message_store,
|
./storage/message/waku_message_store,
|
||||||
./storage/peer/waku_peer_storage
|
./storage/peer/waku_peer_storage
|
||||||
|
|
||||||
|
|
|
@ -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…
Reference in New Issue