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
@@ -0,0 +1,62 @@
|
||||
import {
|
||||
ScratchDatabase,
|
||||
createScratchDatabase,
|
||||
} from './utils/migration-harness';
|
||||
|
||||
const BACKFILL = '20261021100000_queen_deactivated_backfill';
|
||||
|
||||
const TIMEOUT_MS = 240_000;
|
||||
|
||||
describe('Queen deactivatedAt backfill migration (e2e)', () => {
|
||||
let db: ScratchDatabase | undefined;
|
||||
|
||||
afterEach(async () => {
|
||||
await db?.drop();
|
||||
db = undefined;
|
||||
});
|
||||
|
||||
it(
|
||||
'dates every unavailable queen without deactivatedAt by her last colony end, else her last change, and leaves the rest alone',
|
||||
async () => {
|
||||
db = await createScratchDatabase(BACKFILL);
|
||||
await db.query(
|
||||
`INSERT INTO "Apiary" ("id", "name", "updatedAt") VALUES ('apiary-1', 'Stand', now())`,
|
||||
);
|
||||
await db.query(
|
||||
`INSERT INTO "Colony" ("id", "code", "apiaryId", "colonyType", "updatedAt")
|
||||
VALUES ('colony-1', 'V-1', 'apiary-1', 'PRODUCTION_COLONY', now())`,
|
||||
);
|
||||
await db.query(
|
||||
`INSERT INTO "Queen" ("id", "code", "status", "updatedAt", "deactivatedAt") VALUES
|
||||
('q-dead-history', 'Q-1', 'DECEASED', '2026-09-01T00:00:00Z', NULL),
|
||||
('q-sold-nohistory', 'Q-2', 'SOLD', '2026-08-15T00:00:00Z', NULL),
|
||||
('q-lost-dated', 'Q-3', 'LOST', '2026-07-01T00:00:00Z', '2026-06-01T00:00:00Z'),
|
||||
('q-active', 'Q-4', 'ACTIVE', '2026-09-01T00:00:00Z', NULL),
|
||||
('q-replaced-open', 'Q-5', 'REPLACED', '2026-09-10T00:00:00Z', NULL)`,
|
||||
);
|
||||
await db.query(
|
||||
`INSERT INTO "QueenColonyHistory" ("id", "queenId", "colonyId", "startDate", "endDate") VALUES
|
||||
('h-1', 'q-dead-history', 'colony-1', '2025-04-01T00:00:00Z', '2025-10-01T00:00:00Z'),
|
||||
('h-2', 'q-dead-history', 'colony-1', '2026-03-01T00:00:00Z', '2026-05-20T00:00:00Z'),
|
||||
('h-3', 'q-active', 'colony-1', '2026-05-20T00:00:00Z', NULL),
|
||||
('h-4', 'q-replaced-open', 'colony-1', '2026-01-01T00:00:00Z', NULL)`,
|
||||
);
|
||||
|
||||
await db.migrateThrough(BACKFILL);
|
||||
|
||||
expect(
|
||||
await db.query(
|
||||
`SELECT "id", to_char("deactivatedAt", 'YYYY-MM-DD') AS "deactivatedOn"
|
||||
FROM "Queen" ORDER BY "id"`,
|
||||
),
|
||||
).toEqual([
|
||||
{ id: 'q-active', deactivatedOn: null },
|
||||
{ id: 'q-dead-history', deactivatedOn: '2026-05-20' },
|
||||
{ id: 'q-lost-dated', deactivatedOn: '2026-06-01' },
|
||||
{ id: 'q-replaced-open', deactivatedOn: '2026-09-10' },
|
||||
{ id: 'q-sold-nohistory', deactivatedOn: '2026-08-15' },
|
||||
]);
|
||||
},
|
||||
TIMEOUT_MS,
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user