Skip to content

Commit e180535

Browse files
authored
fix: order platform saga query by version for deterministic migration (#1452)
* fix: order platform saga query by version for deterministic migration loadPlatformSagas queries all platform_saga_definition rows and stores them in a map keyed by name. When multiple versions exist (e.g., stripe_payment v1/v2/v3), the last row scanned overwrites the entry. Without ORDER BY version, the winning version was non-deterministic, causing migration tests to fail when an older version won and the similarity check against the tenant's latest-version script dropped below threshold (69% vs required 95%). * fix: use semver-aware ordering for platform saga version selection The version column is VARCHAR with semver format (X.Y.Z). Lexical ordering would misorder multi-digit versions (1.10.0 < 1.2.0). Use string_to_array with integer casting for correct numeric comparison. --------- Co-authored-by: Ben Coombs <bjcoombs@users.noreply.github.com>
1 parent 765be40 commit e180535

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

services/reference-data/saga/override_api.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,10 @@ func (s *OverrideService) loadPlatformSagas(ctx context.Context) (map[string]Pla
412412
rows, err := s.pool.Query(ctx, `
413413
SELECT id, name, version, script, display_name, description
414414
FROM public.platform_saga_definition
415-
ORDER BY name`)
415+
ORDER BY name,
416+
(string_to_array(version, '.'))[1]::INT,
417+
(string_to_array(version, '.'))[2]::INT,
418+
(string_to_array(version, '.'))[3]::INT`)
416419
if err != nil {
417420
return nil, fmt.Errorf("query platform sagas: %w", err)
418421
}

0 commit comments

Comments
 (0)