From 1b9057d67db1c688b4126da588c84ee585a80452 Mon Sep 17 00:00:00 2001 From: hgw Date: Fri, 2 Feb 2024 02:45:36 +0000 Subject: [PATCH] Accept db connection string --- server/plugins/messageStorage/sqlite.ts | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/server/plugins/messageStorage/sqlite.ts b/server/plugins/messageStorage/sqlite.ts index a16434e4..b34c2417 100644 --- a/server/plugins/messageStorage/sqlite.ts +++ b/server/plugins/messageStorage/sqlite.ts @@ -126,19 +126,8 @@ class SqliteMessageStorage implements SearchableMessageStorage { this.initDone = new Deferred(); } - async _enable() { - const logsPath = Config.getUserLogsPath(); - const sqlitePath = path.join(logsPath, `${this.userName}.sqlite3`); - - try { - await fs.mkdir(logsPath, { recursive: true }); - } catch (e) { - throw Helper.catch_to_error("Unable to create logs directory", e); - } - - this.isEnabled = true; - - this.database = new sqlite3.Database(sqlitePath); + async _enable(connection_string: string) { + this.database = new sqlite3.Database(connection_string); try { await this.run_pragmas(); // must be done outside of a transaction @@ -147,11 +136,22 @@ class SqliteMessageStorage implements SearchableMessageStorage { this.isEnabled = false; throw Helper.catch_to_error("Migration failed", e); } + + this.isEnabled = true; } async enable() { + const logsPath = Config.getUserLogsPath(); + const sqlitePath = path.join(logsPath, `${this.userName}.sqlite3`); + try { - await this._enable(); + await fs.mkdir(logsPath, {recursive: true}); + } catch (e) { + throw Helper.catch_to_error("Unable to create logs directory", e); + } + + try { + await this._enable(sqlitePath); } finally { this.initDone.resolve(); // unblock the instance methods }