refactor of node config so that node config upgrade inserts are handled distinctly from any other config inserts that may come in future (#2609)
This commit is contained in:
parent
81b7a505c7
commit
3dd13e3642
|
@ -325,8 +325,8 @@ func insertClusterConfigNodes(tx *sql.Tx, c *params.NodeConfig) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func SaveConfigWithTx(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
insertFNs := []insertFn{
|
||||
func nodeConfigUpgradeInserts() []insertFn {
|
||||
return []insertFn{
|
||||
insertNodeConfig,
|
||||
insertHTTPConfig,
|
||||
insertIPCConfig,
|
||||
|
@ -343,10 +343,11 @@ func SaveConfigWithTx(tx *sql.Tx, c *params.NodeConfig) error {
|
|||
insertShhExtConfig,
|
||||
insertWakuConfig,
|
||||
insertWakuV2Config,
|
||||
insertTorrentConfig,
|
||||
}
|
||||
}
|
||||
|
||||
for _, fn := range insertFNs {
|
||||
func execInsertFns(inFn []insertFn, tx *sql.Tx, c *params.NodeConfig) error {
|
||||
for _, fn := range inFn {
|
||||
err := fn(tx, c)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -356,6 +357,18 @@ func SaveConfigWithTx(tx *sql.Tx, c *params.NodeConfig) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertNodeConfigUpgrade(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
return execInsertFns(nodeConfigUpgradeInserts(), tx, c)
|
||||
}
|
||||
|
||||
func SaveConfigWithTx(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
insertFNs := append(nodeConfigUpgradeInserts(),
|
||||
insertTorrentConfig,
|
||||
)
|
||||
|
||||
return execInsertFns(insertFNs, tx, c)
|
||||
}
|
||||
|
||||
func SaveNodeConfig(db *sql.DB, c *params.NodeConfig) error {
|
||||
tx, err := db.BeginTx(context.Background(), &sql.TxOptions{})
|
||||
if err != nil {
|
||||
|
@ -387,7 +400,7 @@ func migrateNodeConfig(tx *sql.Tx) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
err = SaveConfigWithTx(tx, nodecfg)
|
||||
err = insertNodeConfigUpgrade(tx, nodecfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue