From 7bbaeffd3e7bc26f938cf8394d30aa738f87d572 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Fri, 8 Apr 2022 00:56:56 +0800 Subject: [PATCH] Fix reset-password (issue caused by 5027fcd320fe7fbf09d8742c8f6d5e3538e2c380) --- extra/reset-password.js | 5 ++--- server/database.js | 17 +++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/extra/reset-password.js b/extra/reset-password.js index 1b48dffd..160ef0a3 100644 --- a/extra/reset-password.js +++ b/extra/reset-password.js @@ -1,7 +1,5 @@ console.log("== Uptime Kuma Reset Password Tool =="); -console.log("Loading the database"); - const Database = require("../server/database"); const { R } = require("redbean-node"); const readline = require("readline"); @@ -13,8 +11,9 @@ const rl = readline.createInterface({ }); const main = async () => { + console.log("Connecting the database"); Database.init(args); - await Database.connect(); + await Database.connect(false, false, true); try { // No need to actually reset the password for testing, just make sure no connection problem. It is ok for now. diff --git a/server/database.js b/server/database.js index 156c295b..69b0fd3c 100644 --- a/server/database.js +++ b/server/database.js @@ -83,7 +83,7 @@ class Database { console.log(`Data Dir: ${Database.dataDir}`); } - static async connect(testMode = false) { + static async connect(testMode = false, autoloadModels = true, noLog = false) { const acquireConnectionTimeout = 120 * 1000; const Dialect = require("knex/lib/dialects/sqlite3/index.js"); @@ -113,7 +113,10 @@ class Database { // Auto map the model to a bean object R.freeze(true); - await R.autoloadModels("./server/model"); + + if (autoloadModels) { + await R.autoloadModels("./server/model"); + } await R.exec("PRAGMA foreign_keys = ON"); if (testMode) { @@ -126,10 +129,12 @@ class Database { await R.exec("PRAGMA cache_size = -12000"); await R.exec("PRAGMA auto_vacuum = FULL"); - console.log("SQLite config:"); - console.log(await R.getAll("PRAGMA journal_mode")); - console.log(await R.getAll("PRAGMA cache_size")); - console.log("SQLite Version: " + await R.getCell("SELECT sqlite_version()")); + if (!noLog) { + console.log("SQLite config:"); + console.log(await R.getAll("PRAGMA journal_mode")); + console.log(await R.getAll("PRAGMA cache_size")); + console.log("SQLite Version: " + await R.getCell("SELECT sqlite_version()")); + } } static async patch() {