Files
tasks/service/worker/migration/execution_info.go
Yichao YangandVladyslav Simonenko d0ca617050 Fix migration workflow breaking change for OSS (#9085)
## What changed?
- Use plain go struct inside migration workflow activity input output
- Customize the json encoding/decoding for migration execution info and
make it backward & forward compatible.
- This will temporary break cloud and the fix is in
https://github.com/temporalio/temporal/pull/9097
- This PR needs to be part of oss v1.30 release.

## Why?
- Backward compatibility and less confusion over how the encoding will
be done.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [ ] covered by existing tests
- [x] added new unit test(s)
- [ ] added new functional test(s)
2026-01-26 16:58:08 -08:00

52 lines
1.3 KiB
Go

package migration
import (
"encoding/json"
)
type ExecutionInfo struct {
executionInfoNewJSON
}
type executionInfoNewJSON struct {
BusinessID string `json:"business_id,omitempty"`
RunID string `json:"run_id,omitempty"`
ArchetypeID uint32 `json:"archetype_id,omitempty"`
}
type executionInfoLegacyJSON struct {
BusinessID string `json:"business_id,omitempty"`
WorkflowID string `json:"workflow_id,omitempty"`
RunID string `json:"run_id,omitempty"`
ArchetypeID uint32 `json:"archetype_id,omitempty"`
}
func (e *ExecutionInfo) MarshalJSON() ([]byte, error) {
return json.Marshal(executionInfoLegacyJSON{
WorkflowID: e.BusinessID,
RunID: e.RunID,
ArchetypeID: e.ArchetypeID,
})
}
func (e *ExecutionInfo) UnmarshalJSON(data []byte) error {
// For forward compatibility, support both workflow_id and business_id here.
// Then in v1.31, we can always encode using "business_id" and also support downgrade.
var legacy executionInfoLegacyJSON
if err := json.Unmarshal(data, &legacy); err != nil {
return err
}
businessID := legacy.WorkflowID
if legacy.BusinessID != "" {
businessID = legacy.BusinessID
}
e.executionInfoNewJSON = executionInfoNewJSON{
BusinessID: businessID,
RunID: legacy.RunID,
ArchetypeID: legacy.ArchetypeID,
}
return nil
}