Centralize device row update transactions
This commit is contained in:
@@ -21,11 +21,10 @@ It must support circuits, device rows, project devices, drag-and-drop restructur
|
||||
`src/frontend/components/circuit-grid-*.ts` modules.
|
||||
- Critical multi-write commands use injected transaction repositories with real
|
||||
SQLite commit/rollback tests.
|
||||
- Compatible command stores for Circuit and ProjectDevice field updates,
|
||||
project settings, structure, device-row moves, section reorder/renumber and
|
||||
project-device row synchronization share
|
||||
- All supported runtime project-command stores share
|
||||
`src/db/repositories/project-command-transaction.persistence.ts` for the
|
||||
atomic domain-write, revision and history transition boundary.
|
||||
atomic domain-write, revision and history transition boundary. Its applied
|
||||
forward-command variant preserves derived CircuitDeviceRow override metadata.
|
||||
- General Circuit, CircuitDeviceRow, CircuitList and DistributionBoard
|
||||
repositories expose only active reads. Runtime writes belong in typed command
|
||||
repositories; direct integration fixtures belong under `tests/support`.
|
||||
|
||||
@@ -84,15 +84,13 @@ absteigend paginierte Revisions-Timeline ist ohne Befehls-Payloads über
|
||||
`GET /api/projects/:projectId/history/revisions` lesbar. Ein zentraler
|
||||
Dispatcher führt die nachfolgend beschriebenen typisierten Kommandos über
|
||||
öffentliche Command-, Undo- und Redo-Endpunkte aus.
|
||||
Die kompatiblen Command-Stores für Circuit- und ProjectDevice-Feldänderungen,
|
||||
Projekteinstellungen, Circuit-/CircuitDeviceRow-Struktur, Gerätezeilen-Moves,
|
||||
Abschnittssortierung/-umnummerierung, DistributionBoard-Struktur,
|
||||
ProjectDevice-Struktur und -Zeilensynchronisierung sowie Geschoss/Raum verwenden
|
||||
dabei
|
||||
Alle unterstützten Runtime-Project-Command-Stores verwenden dabei
|
||||
`project-command-transaction.persistence.ts` als gemeinsame äußere
|
||||
Transaktionsgrenze. Sie führt Fachänderung, Revisions-Append und
|
||||
History-Transition in fester Reihenfolge innerhalb derselben SQLite-Transaktion
|
||||
aus; die fachlichen Validierungs- und Inversenregeln bleiben im jeweiligen
|
||||
aus. Für CircuitDeviceRow-Feldänderungen übernimmt eine typisierte Variante den
|
||||
während der Fachänderung um Override-Metadaten ergänzten Forward-Command. Die
|
||||
fachlichen Validierungs-, Forward- und Inversenregeln bleiben im jeweiligen
|
||||
Store.
|
||||
`circuit-device-row.insert` und `circuit-device-row.delete` sind atomare
|
||||
Strukturkommandos. Beim Löschen wird die vollständige Zeile im inversen
|
||||
|
||||
@@ -346,10 +346,9 @@ Implemented foundation:
|
||||
- obsolete direct Circuit, CircuitDeviceRow, CircuitList, DistributionBoard and
|
||||
Project repository writes are removed; integration fixtures live under
|
||||
`tests/support` instead of production repositories
|
||||
- compatible Circuit/ProjectDevice update, project-settings, structure,
|
||||
device-row move, section reorder/renumber, ProjectDevice row-sync and
|
||||
project-location stores share one tested transaction wrapper for domain
|
||||
mutation, revision append and history transition
|
||||
- all supported runtime project-command stores share one tested transaction
|
||||
wrapper for domain mutation, revision append and history transition; its
|
||||
applied-forward variant retains derived CircuitDeviceRow override metadata
|
||||
- the legacy consumer UI and application read/write endpoints are removed after verified data cutover
|
||||
- retained legacy rows are accessible only through explicit database upgrade tooling
|
||||
- project devices no longer persist duplicate legacy power, phase, cosPhi or remark fields
|
||||
|
||||
@@ -21,8 +21,7 @@ import {
|
||||
toCircuitDeviceRowPatchValues,
|
||||
type CircuitDeviceRowPatchInput,
|
||||
} from "./circuit-device-row.persistence.js";
|
||||
import { applyProjectHistoryTransition } from "./project-history.persistence.js";
|
||||
import { appendProjectRevision } from "./project-revision.persistence.js";
|
||||
import { executeProjectCommandTransactionWithAppliedForward } from "./project-command-transaction.persistence.js";
|
||||
|
||||
type CircuitDeviceRow = typeof circuitDeviceRows.$inferSelect;
|
||||
|
||||
@@ -34,7 +33,17 @@ export class CircuitDeviceRowProjectCommandRepository
|
||||
executeUpdate(input: ExecuteCircuitDeviceRowUpdateCommandInput) {
|
||||
assertCircuitDeviceRowUpdateProjectCommand(input.command);
|
||||
|
||||
return this.database.transaction((tx) => {
|
||||
return executeProjectCommandTransactionWithAppliedForward(
|
||||
this.database,
|
||||
input,
|
||||
(tx) => this.applyCommand(tx, input)
|
||||
);
|
||||
}
|
||||
|
||||
private applyCommand(
|
||||
tx: AppDatabase,
|
||||
input: ExecuteCircuitDeviceRowUpdateCommandInput
|
||||
) {
|
||||
const current = tx
|
||||
.select()
|
||||
.from(circuitDeviceRows)
|
||||
@@ -109,24 +118,10 @@ export class CircuitDeviceRowProjectCommandRepository
|
||||
throw new Error("Circuit device row changed before command execution.");
|
||||
}
|
||||
|
||||
const revision = appendProjectRevision(tx, {
|
||||
projectId: input.projectId,
|
||||
expectedRevision: input.expectedRevision,
|
||||
source: input.source,
|
||||
description: input.description,
|
||||
actorId: input.actorId,
|
||||
return {
|
||||
forward: appliedForward,
|
||||
inverse,
|
||||
});
|
||||
applyProjectHistoryTransition(tx, {
|
||||
projectId: input.projectId,
|
||||
source: input.source,
|
||||
recordedChangeSetId: revision.changeSetId,
|
||||
targetChangeSetId: input.historyTargetChangeSetId,
|
||||
});
|
||||
|
||||
return { revision, inverse };
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
private assertLinkedProjectDevice(
|
||||
|
||||
@@ -19,6 +19,14 @@ export interface ProjectCommandTransactionInput<
|
||||
command: Command;
|
||||
}
|
||||
|
||||
export interface AppliedProjectCommand<
|
||||
Forward extends SerializedProjectCommand<unknown>,
|
||||
Inverse extends SerializedProjectCommand<unknown>,
|
||||
> {
|
||||
forward: Forward;
|
||||
inverse: Inverse;
|
||||
}
|
||||
|
||||
export function executeProjectCommandTransaction<
|
||||
Command extends SerializedProjectCommand<unknown>,
|
||||
Inverse extends SerializedProjectCommand<unknown>,
|
||||
@@ -26,16 +34,55 @@ export function executeProjectCommandTransaction<
|
||||
database: AppDatabase,
|
||||
input: ProjectCommandTransactionInput<Command>,
|
||||
applyCommand: (transaction: AppDatabase) => Inverse
|
||||
): { revision: AppendedProjectRevision; inverse: Inverse } {
|
||||
return executeAppliedProjectCommandTransaction(
|
||||
database,
|
||||
input,
|
||||
(transaction) => ({
|
||||
forward: input.command,
|
||||
inverse: applyCommand(transaction),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function executeProjectCommandTransactionWithAppliedForward<
|
||||
Command extends SerializedProjectCommand<unknown>,
|
||||
Forward extends SerializedProjectCommand<unknown>,
|
||||
Inverse extends SerializedProjectCommand<unknown>,
|
||||
>(
|
||||
database: AppDatabase,
|
||||
input: ProjectCommandTransactionInput<Command>,
|
||||
applyCommand: (
|
||||
transaction: AppDatabase
|
||||
) => AppliedProjectCommand<Forward, Inverse>
|
||||
): { revision: AppendedProjectRevision; inverse: Inverse } {
|
||||
return executeAppliedProjectCommandTransaction(
|
||||
database,
|
||||
input,
|
||||
applyCommand
|
||||
);
|
||||
}
|
||||
|
||||
function executeAppliedProjectCommandTransaction<
|
||||
Command extends SerializedProjectCommand<unknown>,
|
||||
Forward extends SerializedProjectCommand<unknown>,
|
||||
Inverse extends SerializedProjectCommand<unknown>,
|
||||
>(
|
||||
database: AppDatabase,
|
||||
input: ProjectCommandTransactionInput<Command>,
|
||||
applyCommand: (
|
||||
transaction: AppDatabase
|
||||
) => AppliedProjectCommand<Forward, Inverse>
|
||||
): { revision: AppendedProjectRevision; inverse: Inverse } {
|
||||
return database.transaction((tx) => {
|
||||
const inverse = applyCommand(tx);
|
||||
const { forward, inverse } = applyCommand(tx);
|
||||
const revision = appendProjectRevision(tx, {
|
||||
projectId: input.projectId,
|
||||
expectedRevision: input.expectedRevision,
|
||||
source: input.source,
|
||||
description: input.description,
|
||||
actorId: input.actorId,
|
||||
forward: input.command,
|
||||
forward,
|
||||
inverse,
|
||||
});
|
||||
applyProjectHistoryTransition(tx, {
|
||||
|
||||
Reference in New Issue
Block a user