-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_4_1_payload_format.go
44 lines (40 loc) · 1.14 KB
/
2_4_1_payload_format.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright © 2017 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
package migrate
import (
"github.com/TheThingsNetwork/ttn/core/storage"
redis "gopkg.in/redis.v5"
)
// AddPayloadFormat migration from 2.4.1 to 2.6.1
func AddPayloadFormat(prefix string) storage.MigrateFunction {
return func(client *redis.Client, key string, obj map[string]string) (string, map[string]string, error) {
usesCustom := false
if decoder, ok := obj["decoder"]; ok {
delete(obj, "decoder")
obj["custom_decoder"] = decoder
usesCustom = true
}
if converter, ok := obj["converter"]; ok {
delete(obj, "converter")
obj["custom_converter"] = converter
usesCustom = true
}
if validator, ok := obj["validator"]; ok {
delete(obj, "validator")
obj["custom_validator"] = validator
usesCustom = true
}
if encoder, ok := obj["encoder"]; ok {
delete(obj, "encoder")
obj["custom_encoder"] = encoder
usesCustom = true
}
if usesCustom {
obj["payload_format"] = "custom"
}
return "2.6.1", obj, nil
}
}
func init() {
applicationMigrations["2.4.1"] = AddPayloadFormat
}