WIP: building database in knex.js

This commit is contained in:
Louis Lam 2023-02-11 22:21:06 +08:00
parent e4183ee2b7
commit 4056951915
9 changed files with 350 additions and 16 deletions

View file

@ -180,7 +180,12 @@ let needSetup = false;
}
// Connect to database
await initDatabase(testMode);
try {
await initDatabase(testMode);
} catch (e) {
log.error("server", "Failed to prepare your database: " + e.message);
process.exit(1);
}
// Database should be ready now
await server.initAfterDatabaseReady();
@ -1658,11 +1663,6 @@ async function afterLogin(socket, user) {
* @returns {Promise<void>}
*/
async function initDatabase(testMode = false) {
if (! fs.existsSync(Database.sqlitePath)) {
log.info("server", "Copying Database");
fs.copyFileSync(Database.templatePath, Database.sqlitePath);
}
log.info("server", "Connecting to the Database");
await Database.connect(testMode);
log.info("server", "Connected");