53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
const Database = require("better-sqlite3");
|
|
const path = require("node:path");
|
|
|
|
const dbPath = path.resolve("data", "leistungsbilanz.db");
|
|
const db = new Database(dbPath, { readonly: true });
|
|
|
|
const requiredTables = [
|
|
"circuit_sections",
|
|
"circuits",
|
|
"circuit_device_rows",
|
|
"legacy_consumer_circuit_migrations",
|
|
"legacy_consumer_migration_reports",
|
|
];
|
|
|
|
const rows = db
|
|
.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name IN (?, ?, ?, ?, ?)")
|
|
.all(...requiredTables);
|
|
|
|
const existing = new Set(rows.map((row) => row.name));
|
|
const missing = requiredTables.filter((name) => !existing.has(name));
|
|
const requiredProjectDeviceColumns = [
|
|
"phase_type",
|
|
"connection_kind",
|
|
"cost_group",
|
|
"power_per_unit",
|
|
"simultaneity_factor",
|
|
"cos_phi",
|
|
"remark",
|
|
];
|
|
const projectDeviceColumns = new Set(
|
|
db.prepare("PRAGMA table_info(project_devices)").all().map((column) => column.name)
|
|
);
|
|
const missingProjectDeviceColumns = requiredProjectDeviceColumns.filter(
|
|
(name) => !projectDeviceColumns.has(name)
|
|
);
|
|
|
|
console.log("Database:", dbPath);
|
|
console.log("Required tables:", requiredTables.join(", "));
|
|
console.log("Existing tables:", [...existing].join(", ") || "(none)");
|
|
console.log("Required project-device columns:", requiredProjectDeviceColumns.join(", "));
|
|
|
|
if (missing.length > 0) {
|
|
console.error("Missing tables:", missing.join(", "));
|
|
process.exit(1);
|
|
}
|
|
|
|
if (missingProjectDeviceColumns.length > 0) {
|
|
console.error("Missing project-device columns:", missingProjectDeviceColumns.join(", "));
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log("Circuit-first schema verification passed.");
|