Files
Infosec/init-db.js
T
2026-09-13 20:10:17 +01:00

28 lines
885 B
JavaScript

'use strict';
/**
* Prepares the database: creates the schema and seeds the default email
* templates. It is safe to run repeatedly (and the Docker entrypoint runs it
* on every start).
*
* The first administrator is NOT created here — on first boot the site itself
* shows a setup wizard in the browser that asks for the admin account.
*/
require('dotenv').config();
const { db, init, migrate, DB_PATH, reportMissingEmails } = require('./db');
const { seedDefaults } = require('./lib/templates');
init();
migrate();
seedDefaults();
const users = db.prepare('SELECT COUNT(*) c FROM users').get().c;
reportMissingEmails();
console.log(`Database ready at ${DB_PATH}`);
if (users === 0) {
console.log('No users yet — open the site in a browser to create the administrator account.');
} else {
console.log(`${users} user account(s) already present.`);
}
process.exit(0);