Ship configurator updates with catalog DB included for server deploy.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
lejay
2026-10-07 17:13:03 +02:00
co-authored by Cursor
parent 6c0d7e47b8
commit 30921aade6
75 changed files with 15618 additions and 1300 deletions
+35 -2
View File
@@ -14,10 +14,43 @@ if (!fs.existsSync(dbPath)) {
const SQL = await initSqlJs({
locateFile: (file) => path.join(__dirname, '..', 'node_modules', 'sql.js', 'dist', file)
});
function countMaterials(database) {
try {
const result = database.exec('SELECT COUNT(*) AS c FROM formex_materials');
return Number(result[0]?.values?.[0]?.[0] ?? 0);
} catch {
return 0;
}
}
function atomicWrite(filePath, database) {
const tmpPath = `${filePath}.tmp`;
fs.writeFileSync(tmpPath, Buffer.from(database.export()));
try {
fs.renameSync(tmpPath, filePath);
} catch {
fs.copyFileSync(tmpPath, filePath);
try { fs.unlinkSync(tmpPath); } catch { /* ignore */ }
}
}
const buffer = fs.readFileSync(dbPath);
const db = new SQL.Database(buffer);
const before = countMaterials(db);
const seedSql = fs.readFileSync(path.join(__dirname, 'seeds.sql'), 'utf8');
db.exec(seedSql);
fs.writeFileSync(dbPath, Buffer.from(db.export()));
const after = countMaterials(db);
if (before > 0 && after < before) {
console.error(
`REFUSING to write seeds: materials would shrink ${before} → ${after}. Aborting.`
);
db.close();
process.exit(1);
}
atomicWrite(dbPath, db);
db.close();
console.log('Seeds applied.');
console.log(`Seeds applied. Materials preserved: ${after} (was ${before}).`);