Include external models in project snapshots

This commit is contained in:
Julian Appel 2026-08-02 17:25:25 +02:00
parent 76493b573e
commit e87a3289fa
10 changed files with 685 additions and 15 deletions

View file

@ -21,6 +21,10 @@ import { projectDevices } from "../schema/project-devices.js";
import { projects } from "../schema/projects.js";
import { rooms } from "../schema/rooms.js";
import { externalCsvConfigurations } from "../schema/external-csv-configurations.js";
import { externalImportBatches } from "../schema/external-import-batches.js";
import { externalModelObjects } from "../schema/external-model-objects.js";
import { externalModelSources } from "../schema/external-model-sources.js";
import { externalRoomMappings } from "../schema/external-room-mappings.js";
import {
hashProjectStatePayload,
readProjectStateSnapshot,
@ -157,6 +161,21 @@ function insertProjectState(
circuitDeviceRows,
state.circuits.flatMap((circuit) => circuit.deviceRows)
);
if (state.externalModel.source !== null) {
database.insert(externalModelSources).values(state.externalModel.source).run();
}
insertMany(
database,
externalImportBatches,
state.externalModel.importBatches.map(
({ originalContentBase64, ...batch }) => ({
...batch,
originalBytes: Buffer.from(originalContentBase64, "base64"),
})
)
);
insertMany(database, externalRoomMappings, state.externalModel.roomMappings);
insertMany(database, externalModelObjects, state.externalModel.objects);
}
function insertMany<TTable extends Parameters<AppDatabase["insert"]>[0]>(