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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SaveConfigWithTx(tx *sql.Tx, c *params.NodeConfig) error {
|
func nodeConfigUpgradeInserts() []insertFn {
|
||||||
insertFNs := []insertFn{
|
return []insertFn{
|
||||||
insertNodeConfig,
|
insertNodeConfig,
|
||||||
insertHTTPConfig,
|
insertHTTPConfig,
|
||||||
insertIPCConfig,
|
insertIPCConfig,
|
||||||
|
@ -343,10 +343,11 @@ func SaveConfigWithTx(tx *sql.Tx, c *params.NodeConfig) error {
|
||||||
insertShhExtConfig,
|
insertShhExtConfig,
|
||||||
insertWakuConfig,
|
insertWakuConfig,
|
||||||
insertWakuV2Config,
|
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)
|
err := fn(tx, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -356,6 +357,18 @@ func SaveConfigWithTx(tx *sql.Tx, c *params.NodeConfig) error {
|
||||||
return nil
|
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 {
|
func SaveNodeConfig(db *sql.DB, c *params.NodeConfig) error {
|
||||||
tx, err := db.BeginTx(context.Background(), &sql.TxOptions{})
|
tx, err := db.BeginTx(context.Background(), &sql.TxOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -387,7 +400,7 @@ func migrateNodeConfig(tx *sql.Tx) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = SaveConfigWithTx(tx, nodecfg)
|
err = insertNodeConfigUpgrade(tx, nodecfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue