Documentation

This commit is contained in:
2026-05-07 22:55:15 +02:00
parent b1e19a88d5
commit 7580ad0ade
11 changed files with 584 additions and 1 deletions
@@ -141,6 +141,8 @@ export class CircuitRepository {
if (updates.length === 0) {
return;
}
// better-sqlite3 transactions are synchronous callbacks. Do not make this callback
// async or return a Promise, otherwise statements may run outside the transaction scope.
db.transaction((tx) => {
const ids = updates.map((entry) => entry.id);
const existing = tx
@@ -152,6 +154,10 @@ export class CircuitRepository {
throw new Error("One or more circuit ids are invalid for circuit list.");
}
// Direct identifier swaps can violate UNIQUE(circuit_list_id, equipment_identifier)
// mid-update (for example A->B while B->A). Two-phase strategy prevents that:
// 1) assign unique temporary identifiers for all affected circuits
// 2) assign final user-visible identifiers
const stamp = Date.now();
for (let index = 0; index < updates.length; index += 1) {
const entry = updates[index];