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:
Samuel Hawksby-Robinson 2022-03-25 18:34:24 +00:00 committed by GitHub
parent 81b7a505c7
commit 3dd13e3642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View File

@ -1 +1 @@
0.97.1 0.97.3

View File

@ -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
} }