Skip to content

Commit 04e094b

Browse files
authored
Merge pull request #1338 from nyaruka/fix_empty_cate_names
Amend 14.0 migration to also fix empty category names
2 parents 39ccf15 + 42ffcea commit 04e094b

File tree

2 files changed

+99
-2
lines changed

2 files changed

+99
-2
lines changed

flows/definition/migrations/13_x.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ func init() {
2424
registerMigration(semver.MustParse("13.1.0"), Migrate13_1)
2525
}
2626

27-
// Migrate14.0 fixes invalid expires values. Note that this is a major version change because of other additions to the
28-
// flow spec that don't require migration.
27+
// Migrate14.0 fixes invalid expires values and categories with missing names.
28+
// Note that this is a major version change because of other additions to the flow spec that don't require migration.
2929
//
3030
// @version 14_0 "14.0"
3131
func Migrate14_0(f Flow, cfg *Config) (Flow, error) {
@@ -45,6 +45,22 @@ func Migrate14_0(f Flow, cfg *Config) (Flow, error) {
4545
}
4646
}
4747

48+
for _, node := range f.Nodes() {
49+
router := node.Router()
50+
if router != nil {
51+
categories, _ := router["categories"].([]any)
52+
for _, cat := range categories {
53+
category, _ := cat.(map[string]any)
54+
if category != nil {
55+
name, _ := category["name"].(string)
56+
if name == "" {
57+
category["name"] = "Match"
58+
}
59+
}
60+
}
61+
}
62+
}
63+
4864
return f, nil
4965
}
5066

flows/definition/migrations/testdata/migrations/14.0.0.json

+81
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,86 @@
8888
"localization": {},
8989
"nodes": []
9090
}
91+
},
92+
{
93+
"description": "flow with empty category name",
94+
"original": {
95+
"uuid": "25a2d8b2-ae7c-4fed-964a-506fb8c3f0c0",
96+
"name": "Test Flow",
97+
"spec_version": "13.6.1",
98+
"language": "eng",
99+
"type": "messaging",
100+
"localization": {},
101+
"nodes": [
102+
{
103+
"uuid": "4c83851e-f0bf-4c59-ba11-220ecccfcebb",
104+
"router": {
105+
"type": "switch",
106+
"categories": [
107+
{
108+
"uuid": "3c9edf35-7386-4d1c-9d37-fd1b4fa68792",
109+
"name": "",
110+
"exit_uuid": "fc2fcd23-7c4a-44bd-a8c6-6c88e6ed09f8"
111+
},
112+
{
113+
"uuid": "37d8813f-1402-4ad2-9cc2-e9054a96525b",
114+
"name": "Other",
115+
"exit_uuid": "d3356ec1-1686-4c64-8a51-ee36129e48ae"
116+
}
117+
],
118+
"default_category_uuid": "37d8813f-1402-4ad2-9cc2-e9054a96525b",
119+
"operand": "@input.text",
120+
"cases": []
121+
},
122+
"exits": [
123+
{
124+
"uuid": "fc2fcd23-7c4a-44bd-a8c6-6c88e6ed09f8"
125+
},
126+
{
127+
"uuid": "d3356ec1-1686-4c64-8a51-ee36129e48ae"
128+
}
129+
]
130+
}
131+
]
132+
},
133+
"migrated": {
134+
"uuid": "25a2d8b2-ae7c-4fed-964a-506fb8c3f0c0",
135+
"name": "Test Flow",
136+
"spec_version": "14.0.0",
137+
"language": "eng",
138+
"type": "messaging",
139+
"localization": {},
140+
"nodes": [
141+
{
142+
"uuid": "4c83851e-f0bf-4c59-ba11-220ecccfcebb",
143+
"router": {
144+
"type": "switch",
145+
"categories": [
146+
{
147+
"uuid": "3c9edf35-7386-4d1c-9d37-fd1b4fa68792",
148+
"name": "Match",
149+
"exit_uuid": "fc2fcd23-7c4a-44bd-a8c6-6c88e6ed09f8"
150+
},
151+
{
152+
"uuid": "37d8813f-1402-4ad2-9cc2-e9054a96525b",
153+
"name": "Other",
154+
"exit_uuid": "d3356ec1-1686-4c64-8a51-ee36129e48ae"
155+
}
156+
],
157+
"default_category_uuid": "37d8813f-1402-4ad2-9cc2-e9054a96525b",
158+
"operand": "@input.text",
159+
"cases": []
160+
},
161+
"exits": [
162+
{
163+
"uuid": "fc2fcd23-7c4a-44bd-a8c6-6c88e6ed09f8"
164+
},
165+
{
166+
"uuid": "d3356ec1-1686-4c64-8a51-ee36129e48ae"
167+
}
168+
]
169+
}
170+
]
171+
}
91172
}
92173
]

0 commit comments

Comments
 (0)