Added 1B, 2 and added bootstrap again for site
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { CircuitListRepository } from "../src/db/repositories/circuit-list.repository.js";
|
||||
import { CircuitSectionRepository } from "../src/db/repositories/circuit-section.repository.js";
|
||||
import { ProjectRepository } from "../src/db/repositories/project.repository.js";
|
||||
|
||||
const projectRepository = new ProjectRepository();
|
||||
const circuitListRepository = new CircuitListRepository();
|
||||
const circuitSectionRepository = new CircuitSectionRepository();
|
||||
|
||||
async function run() {
|
||||
const projects = await projectRepository.list();
|
||||
let totalLists = 0;
|
||||
for (const project of projects) {
|
||||
const lists = await circuitListRepository.listByProject(project.id);
|
||||
for (const list of lists) {
|
||||
await circuitSectionRepository.createDefaults(list.id);
|
||||
totalLists += 1;
|
||||
}
|
||||
}
|
||||
console.log(`Section backfill done for ${totalLists} circuit list(s).`);
|
||||
}
|
||||
|
||||
run().catch((error) => {
|
||||
console.error("Section backfill failed:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
|
||||
const dataDir = path.resolve("data");
|
||||
const source = path.join(dataDir, "leistungsbilanz.db");
|
||||
|
||||
if (!fs.existsSync(source)) {
|
||||
console.error(`Database file not found: ${source}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const backupDir = path.join(dataDir, "backups");
|
||||
fs.mkdirSync(backupDir, { recursive: true });
|
||||
|
||||
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
||||
const target = path.join(backupDir, `leistungsbilanz-${timestamp}.db`);
|
||||
fs.copyFileSync(source, target);
|
||||
|
||||
console.log(`Backup created: ${target}`);
|
||||
@@ -0,0 +1,36 @@
|
||||
import { CircuitListRepository } from "../src/db/repositories/circuit-list.repository.js";
|
||||
import { ProjectRepository } from "../src/db/repositories/project.repository.js";
|
||||
import { LegacyConsumerMigrationService } from "../src/domain/services/legacy-consumer-migration.service.js";
|
||||
|
||||
const projectRepository = new ProjectRepository();
|
||||
const circuitListRepository = new CircuitListRepository();
|
||||
const migrationService = new LegacyConsumerMigrationService();
|
||||
|
||||
async function run() {
|
||||
const projects = await projectRepository.list();
|
||||
const reports = [];
|
||||
|
||||
for (const project of projects) {
|
||||
const lists = await circuitListRepository.listByProject(project.id);
|
||||
for (const list of lists) {
|
||||
const report = await migrationService.migrateCircuitList(project.id, list.id);
|
||||
reports.push({
|
||||
projectId: project.id,
|
||||
circuitListId: list.id,
|
||||
legacyConsumerCount: report.legacyConsumerCount,
|
||||
createdCircuitCount: report.createdCircuitCount,
|
||||
createdDeviceRowCount: report.createdDeviceRowCount,
|
||||
generatedIdentifiers: report.generatedIdentifiers.length,
|
||||
unassignedRows: report.unassignedRows.length,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Legacy consumer migration summary:");
|
||||
console.table(reports);
|
||||
}
|
||||
|
||||
run().catch((error) => {
|
||||
console.error("Legacy consumer migration failed:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
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));
|
||||
|
||||
console.log("Database:", dbPath);
|
||||
console.log("Required tables:", requiredTables.join(", "));
|
||||
console.log("Existing tables:", [...existing].join(", ") || "(none)");
|
||||
|
||||
if (missing.length > 0) {
|
||||
console.error("Missing tables:", missing.join(", "));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log("Circuit-first schema verification passed.");
|
||||
@@ -0,0 +1,40 @@
|
||||
import { CircuitDeviceRowRepository } from "../src/db/repositories/circuit-device-row.repository.js";
|
||||
import { CircuitRepository } from "../src/db/repositories/circuit.repository.js";
|
||||
|
||||
async function run() {
|
||||
const circuitId = process.argv[2];
|
||||
if (!circuitId) {
|
||||
console.error("Usage: npm run dev:add-manual-circuit-row -- <circuitId>");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const circuitRepository = new CircuitRepository();
|
||||
const rowRepository = new CircuitDeviceRowRepository();
|
||||
|
||||
const circuit = await circuitRepository.findById(circuitId);
|
||||
if (!circuit) {
|
||||
console.error(`Circuit not found: ${circuitId}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const rowCount = await rowRepository.countByCircuit(circuitId);
|
||||
const createdRowId = await rowRepository.create({
|
||||
circuitId,
|
||||
sortOrder: (rowCount + 1) * 10,
|
||||
name: "Test sub device",
|
||||
displayName: "Beleuchtung WC",
|
||||
phaseType: "single_phase",
|
||||
quantity: 1,
|
||||
powerPerUnit: 0.05,
|
||||
simultaneityFactor: 1,
|
||||
cosPhi: 1,
|
||||
});
|
||||
|
||||
console.log(`Created test row id: ${createdRowId}`);
|
||||
}
|
||||
|
||||
run().catch((error) => {
|
||||
console.error("Failed to create test row:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { CircuitDeviceRowRepository } from "../src/db/repositories/circuit-device-row.repository.js";
|
||||
|
||||
async function run() {
|
||||
const rowId = process.argv[2];
|
||||
if (!rowId) {
|
||||
console.error("Usage: npm run dev:delete-circuit-row -- <rowId>");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const rowRepository = new CircuitDeviceRowRepository();
|
||||
const row = await rowRepository.findById(rowId);
|
||||
if (!row) {
|
||||
console.error(`Row not found: ${rowId}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await rowRepository.delete(rowId);
|
||||
console.log(`Deleted row id: ${rowId}`);
|
||||
}
|
||||
|
||||
run().catch((error) => {
|
||||
console.error("Failed to delete row:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user