mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-04-30 21:21:42 +03:00
Pull request 1781: 5627-fix-migration
Updates #5627. Squashed commit of the following: commit 018ead11959efeaace5312b5990ad82b6fa1f72d Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Fri Mar 24 12:48:25 2023 +0300 home: fix more commit 4bc57a07412bfb7fb7e6c88c14037c567c94d373 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Fri Mar 24 12:32:57 2023 +0300 home: fix statistics migration
This commit is contained in:
parent
8de994d077
commit
0bc3ef89ea
2 changed files with 41 additions and 5 deletions
internal/home
|
@ -839,9 +839,9 @@ func upgradeSchema14to15(diskConf yobj) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type temp struct {
|
type temp struct {
|
||||||
|
val any
|
||||||
from string
|
from string
|
||||||
to string
|
to string
|
||||||
val any
|
|
||||||
}
|
}
|
||||||
replaces := []temp{
|
replaces := []temp{
|
||||||
{from: "querylog_enabled", to: "enabled", val: true},
|
{from: "querylog_enabled", to: "enabled", val: true},
|
||||||
|
@ -876,6 +876,18 @@ func upgradeSchema14to15(diskConf yobj) (err error) {
|
||||||
// 'enabled': true
|
// 'enabled': true
|
||||||
// 'interval': 1
|
// 'interval': 1
|
||||||
// 'ignored': []
|
// 'ignored': []
|
||||||
|
//
|
||||||
|
// If statistics were disabled:
|
||||||
|
//
|
||||||
|
// # BEFORE:
|
||||||
|
// 'dns':
|
||||||
|
// 'statistics_interval': 0
|
||||||
|
//
|
||||||
|
// # AFTER:
|
||||||
|
// 'statistics':
|
||||||
|
// 'enabled': false
|
||||||
|
// 'interval': 1
|
||||||
|
// 'ignored': []
|
||||||
func upgradeSchema15to16(diskConf yobj) (err error) {
|
func upgradeSchema15to16(diskConf yobj) (err error) {
|
||||||
log.Printf("Upgrade yaml: 15 to 16")
|
log.Printf("Upgrade yaml: 15 to 16")
|
||||||
diskConf["schema_version"] = 16
|
diskConf["schema_version"] = 16
|
||||||
|
@ -897,10 +909,23 @@ func upgradeSchema15to16(diskConf yobj) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const field = "statistics_interval"
|
const field = "statistics_interval"
|
||||||
v, has := dns[field]
|
statsIvlVal, has := dns[field]
|
||||||
if has {
|
if has {
|
||||||
stats["enabled"] = v != 0
|
var statsIvl int
|
||||||
stats["interval"] = v
|
statsIvl, ok = statsIvlVal.(int)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type of dns.statistics_interval: %T", statsIvlVal)
|
||||||
|
}
|
||||||
|
|
||||||
|
if statsIvl == 0 {
|
||||||
|
// Set the interval to the default value of one day to make sure
|
||||||
|
// that it passes the validations.
|
||||||
|
stats["interval"] = 1
|
||||||
|
stats["enabled"] = false
|
||||||
|
} else {
|
||||||
|
stats["interval"] = statsIvl
|
||||||
|
stats["enabled"] = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
delete(dns, field)
|
delete(dns, field)
|
||||||
|
|
||||||
|
@ -1099,6 +1124,12 @@ func upgradeSchema19to20(diskConf yobj) (err error) {
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unexpected type of %s: %T", field, statsIvlVal)
|
return fmt.Errorf("unexpected type of %s: %T", field, statsIvlVal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The initial version of upgradeSchema16to17 did not set the zero
|
||||||
|
// interval to a non-zero one. So, reset it now.
|
||||||
|
if statsIvl == 0 {
|
||||||
|
statsIvl = 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stats[field] = timeutil.Duration{Duration: time.Duration(statsIvl) * timeutil.Day}
|
stats[field] = timeutil.Duration{Duration: time.Duration(statsIvl) * timeutil.Day}
|
||||||
|
|
|
@ -729,7 +729,7 @@ func TestUpgradeSchema15to16(t *testing.T) {
|
||||||
want: yobj{
|
want: yobj{
|
||||||
"statistics": map[string]any{
|
"statistics": map[string]any{
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"interval": 0,
|
"interval": 1,
|
||||||
"ignored": []any{},
|
"ignored": []any{},
|
||||||
},
|
},
|
||||||
"dns": map[string]any{},
|
"dns": map[string]any{},
|
||||||
|
@ -963,6 +963,11 @@ func TestUpgradeSchema19to20(t *testing.T) {
|
||||||
want: timeutil.Duration{Duration: timeutil.Day},
|
want: timeutil.Duration{Duration: timeutil.Day},
|
||||||
wantErr: "",
|
wantErr: "",
|
||||||
name: "success",
|
name: "success",
|
||||||
|
}, {
|
||||||
|
ivl: 0,
|
||||||
|
want: timeutil.Duration{Duration: timeutil.Day},
|
||||||
|
wantErr: "",
|
||||||
|
name: "success",
|
||||||
}, {
|
}, {
|
||||||
ivl: 0.25,
|
ivl: 0.25,
|
||||||
want: 0,
|
want: 0,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue