* config: upgrade schema version: 3 -> 4

This commit is contained in:
Simon Zolin 2019-08-05 12:54:17 +03:00
parent 0c46a70d9a
commit 1b95a85651
1 changed files with 39 additions and 1 deletions

View File

@ -10,7 +10,7 @@ import (
yaml "gopkg.in/yaml.v2" yaml "gopkg.in/yaml.v2"
) )
const currentSchemaVersion = 3 // used for upgrading from old configs to new config const currentSchemaVersion = 4 // used for upgrading from old configs to new config
// Performs necessary upgrade operations if needed // Performs necessary upgrade operations if needed
func upgradeConfig() error { func upgradeConfig() error {
@ -67,6 +67,11 @@ func upgradeConfigSchema(oldVersion int, diskConfig *map[string]interface{}) err
if err != nil { if err != nil {
return err return err
} }
case 3:
err := upgradeSchema3to4(diskConfig)
if err != nil {
return err
}
default: default:
err := fmt.Errorf("configuration file contains unknown schema_version, abort") err := fmt.Errorf("configuration file contains unknown schema_version, abort")
log.Println(err) log.Println(err)
@ -173,6 +178,39 @@ func upgradeSchema2to3(diskConfig *map[string]interface{}) error {
return nil return nil
} }
// Add use_global_blocked_services=true setting for existing "clients" array
func upgradeSchema3to4(diskConfig *map[string]interface{}) error {
log.Printf("%s(): called", _Func())
(*diskConfig)["schema_version"] = 4
clients, ok := (*diskConfig)["clients"]
if !ok {
return nil
}
switch arr := clients.(type) {
case []interface{}:
for i := range arr {
switch c := arr[i].(type) {
case map[interface{}]interface{}:
c["use_global_blocked_services"] = true
default:
continue
}
}
default:
return nil
}
return nil
}
// jump three schemas at once -- this time we just do it sequentially // jump three schemas at once -- this time we just do it sequentially
func upgradeSchema0to3(diskConfig *map[string]interface{}) error { func upgradeSchema0to3(diskConfig *map[string]interface{}) error {
err := upgradeSchema0to1(diskConfig) err := upgradeSchema0to1(diskConfig)