-- Backfill story/task sort_order from trailing numeric part of code.
-- Consistent with parseCodeNumber: no trailing digits → Number.MAX_SAFE_INTEGER (9007199254740991).
-- PBIs are intentionally excluded (they keep drag-and-drop + priority ordering).

UPDATE "stories"
SET sort_order = COALESCE(
  CAST(SUBSTRING(code FROM '[0-9]+$') AS DOUBLE PRECISION),
  9007199254740991
);

UPDATE "tasks"
SET sort_order = COALESCE(
  CAST(SUBSTRING(code FROM '[0-9]+$') AS DOUBLE PRECISION),
  9007199254740991
);
