Browse Source

improve migration runner

pull/1344/head
Bernd Storath 2 years ago
parent
commit
41b0ed936b
  1. 2
      Dockerfile
  2. 2
      Dockerfile.dev
  3. 16
      src/services/database/lowdb.ts
  4. 4
      src/services/database/migrations/index.ts

2
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 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 # Set Environment
ENV DEBUG=Server,WireGuard ENV DEBUG=Server,WireGuard,LowDB
ENV PORT=51821 ENV PORT=51821
# Run Web UI # Run Web UI

2
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 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 # Set Environment
ENV DEBUG=Server,WireGuard ENV DEBUG=Server,WireGuard,LowDB
ENV PORT=51821 ENV PORT=51821

16
src/services/database/lowdb.ts

@ -31,17 +31,15 @@ export default class LowDB extends DatabaseProvider {
*/ */
async connect() { async connect() {
try { try {
// load file db await this.__init();
await this.#db.read(); DEBUG('Running Migrations');
DEBUG('Connected successfully'); await migrationRunner(this.#db);
return; DEBUG('Migrations ran successfully');
} catch (error) { } catch (e) {
DEBUG('Database does not exist : ', error); DEBUG(e);
throw new DatabaseError(DatabaseError.ERROR_INIT);
} }
await this.__init();
await migrationRunner(this.#db);
DEBUG('Connected successfully'); DEBUG('Connected successfully');
} }

4
src/services/database/migrations/index.ts

@ -24,8 +24,8 @@ export async function migrationRunner(db: Low<Database>) {
try { try {
await MIGRATION_LIST[migrationId](db); await MIGRATION_LIST[migrationId](db);
db.data.migrations.push(migrationId); db.data.migrations.push(migrationId);
} catch { } catch (e) {
throw new Error(`Failed to run Migration $`); throw new Error(`Failed to run Migration ${migrationId}: ${e}`);
} }
} }
await db.write(); await db.write();

Loading…
Cancel
Save