diff --git a/Dockerfile b/Dockerfile index 16276e92..e17dff7e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,7 +34,7 @@ RUN apk add --no-cache \ RUN update-alternatives --install /sbin/iptables iptables /sbin/iptables-legacy 10 --slave /sbin/iptables-restore iptables-restore /sbin/iptables-legacy-restore --slave /sbin/iptables-save iptables-save /sbin/iptables-legacy-save # Set Environment -ENV DEBUG=Server,WireGuard +ENV DEBUG=Server,WireGuard,LowDB ENV PORT=51821 # Run Web UI diff --git a/Dockerfile.dev b/Dockerfile.dev index 74383667..d464e989 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -24,5 +24,5 @@ RUN apk add --no-cache \ RUN update-alternatives --install /sbin/iptables iptables /sbin/iptables-legacy 10 --slave /sbin/iptables-restore iptables-restore /sbin/iptables-legacy-restore --slave /sbin/iptables-save iptables-save /sbin/iptables-legacy-save # Set Environment -ENV DEBUG=Server,WireGuard -ENV PORT=51821 \ No newline at end of file +ENV DEBUG=Server,WireGuard,LowDB +ENV PORT=51821 diff --git a/src/services/database/lowdb.ts b/src/services/database/lowdb.ts index 018ee55a..7ed7fbbb 100644 --- a/src/services/database/lowdb.ts +++ b/src/services/database/lowdb.ts @@ -31,17 +31,15 @@ export default class LowDB extends DatabaseProvider { */ async connect() { try { - // load file db - await this.#db.read(); - DEBUG('Connected successfully'); - return; - } catch (error) { - DEBUG('Database does not exist : ', error); + await this.__init(); + DEBUG('Running Migrations'); + await migrationRunner(this.#db); + DEBUG('Migrations ran successfully'); + } catch (e) { + DEBUG(e); + throw new DatabaseError(DatabaseError.ERROR_INIT); } - await this.__init(); - await migrationRunner(this.#db); - DEBUG('Connected successfully'); } diff --git a/src/services/database/migrations/index.ts b/src/services/database/migrations/index.ts index 00161a7c..5546b48c 100644 --- a/src/services/database/migrations/index.ts +++ b/src/services/database/migrations/index.ts @@ -24,8 +24,8 @@ export async function migrationRunner(db: Low) { try { await MIGRATION_LIST[migrationId](db); db.data.migrations.push(migrationId); - } catch { - throw new Error(`Failed to run Migration $`); + } catch (e) { + throw new Error(`Failed to run Migration ${migrationId}: ${e}`); } } await db.write();