Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix migrating directly from 13.2 to 13.5 #1255

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions flows/definition/migrations/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,24 @@
// sorted by earliest first
sort.SliceStable(versions, func(i, j int) bool { return versions[i].LessThan(versions[j]) })

migrated, err := ReadFlow(data)
if err != nil {
return nil, err
}

for _, version := range versions {
migrated, err = registered[version](migrated, cfg)
// we read the flow each time to ensure what we pass to the migration function uses the types it expects
flow, err := ReadFlow(data)
if err != nil {
return nil, err

Check warning on line 101 in flows/definition/migrations/base.go

View check run for this annotation

Codecov / codecov/patch

flows/definition/migrations/base.go#L101

Added line #L101 was not covered by tests
}

flow, err = registered[version](flow, cfg)
if err != nil {
return nil, errors.Wrapf(err, "unable to migrate to version %s", version.String())
}

migrated["spec_version"] = version.String()
flow["spec_version"] = version.String()

data = jsonx.MustMarshal(flow)
}

// finally marshal back to JSON
return jsonx.Marshal(migrated)
return data, nil
}

// Clone clones the given flow definition by replacing all UUIDs using the provided mapping and
Expand Down
85 changes: 85 additions & 0 deletions flows/definition/migrations/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,88 @@ func TestCloneOlderVersion(t *testing.T) {
"nodes": []
}`), cloneJSON, "cloned flow mismatch")
}

func TestMultiVersionMigration(t *testing.T) {
migrated, err := migrations.MigrateToLatest([]byte(`{
"uuid": "e91308d7-7c80-4b0b-9840-7a3484158c8e",
"name": "Test",
"spec_version": "13.2.0",
"type": "messaging",
"revision": 0,
"expire_after_minutes": 1440,
"language": "eng",
"nodes": [
{
"actions": [
{
"attachments": [],
"quick_replies": [
"1",
"2"
],
"templating": {
"template": {
"name": "daily_interaction",
"uuid": "b4533c2d-d00d-4294-8f82-4027ed4c2b96"
},
"uuid": "656b5c50-7c71-4257-9db1-2fa9a3deb84d",
"variables": [
"@results.name"
]
},
"text": "BLAAAH",
"type": "send_msg",
"uuid": "929932aa-8414-4458-9504-f60e42395ca2"
}
],
"exits": [
{
"destination_uuid": "45091f3b-1b8a-4ae5-81eb-11426339e864",
"uuid": "cdc71a39-6429-4edc-8439-d956084e5581"
}
],
"uuid": "12d205d2-4697-411a-9ec4-818ae4471598"
}
]
}`), migrations.DefaultConfig)
require.NoError(t, err)

expected := fmt.Sprintf(`{
"uuid": "e91308d7-7c80-4b0b-9840-7a3484158c8e",
"name": "Test",
"spec_version": "%s",
"type": "messaging",
"revision": 0,
"expire_after_minutes": 1440,
"language": "eng",
"nodes": [
{
"actions": [
{
"attachments": [],
"quick_replies": [
"1",
"2"
],
"template": {
"name": "daily_interaction",
"uuid": "b4533c2d-d00d-4294-8f82-4027ed4c2b96"
},
"template_variables": ["@results.name"],
"text": "BLAAAH",
"type": "send_msg",
"uuid": "929932aa-8414-4458-9504-f60e42395ca2"
}
],
"exits": [
{
"destination_uuid": "45091f3b-1b8a-4ae5-81eb-11426339e864",
"uuid": "cdc71a39-6429-4edc-8439-d956084e5581"
}
],
"uuid": "12d205d2-4697-411a-9ec4-818ae4471598"
}
]
}`, definition.CurrentSpecVersion)
test.AssertEqualJSON(t, []byte(expected), migrated, "flow migration mismatch")
}
Loading