fix(queens): verlorene, eingegangene, ersetzte und verkaufte Königinnen ins Archiv
Die Königinnen-Liste trennt Aktiv und Historie über deactivatedAt, das Backend setzte das Feld aber nie. Jetzt stempelt ein Statuswechsel auf LOST, DECEASED, REPLACED oder SOLD das Datum (update und updateStatusIn), ein korrigierter Status nimmt es wieder weg. Die Migration 20261021100000_queen_deactivated_backfill trägt das Datum für bestehende Königinnen nach (Ende der letzten Volkszuordnung, sonst updatedAt). Auch die Lebensdauer in der Statistik rechnet damit wieder. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
39eee3cdb1
commit
1688e77a89
5 files changed
+227
-3
No files matched your search
+14
@@ -0,0 +1,14 @@
|
||||
-- Queens that died, got lost, were replaced or sold never received a
|
||||
-- deactivatedAt, so the /queens history tab and the queen lifespans in the
|
||||
-- statistics never saw them. The service stamps it from now on; this dates
|
||||
-- the existing ones by the end of their last colony assignment, or by their
|
||||
-- last change when no assignment ever ended.
|
||||
-- Data only and idempotent: it touches only unavailable queens still
|
||||
-- without deactivatedAt (QueenColonyHistory is indexed on queenId).
|
||||
UPDATE "Queen" AS q
|
||||
SET "deactivatedAt" = COALESCE(
|
||||
(SELECT max(h."endDate") FROM "QueenColonyHistory" AS h WHERE h."queenId" = q."id"),
|
||||
q."updatedAt"
|
||||
)
|
||||
WHERE q."status" IN ('LOST', 'DECEASED', 'REPLACED', 'SOLD')
|
||||
AND q."deactivatedAt" IS NULL;
|
||||
Reference in new issue
Block a user