Browse Source

improve migration runner

pull/1344/head
Bernd Storath 2 years ago
parent
commit
41b0ed936b
  1. 2
      Dockerfile
  2. 4
      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
# Set Environment
ENV DEBUG=Server,WireGuard
ENV DEBUG=Server,WireGuard,LowDB
ENV PORT=51821
# Run Web UI

4
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
ENV DEBUG=Server,WireGuard,LowDB
ENV PORT=51821

16
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');
}

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

@ -24,8 +24,8 @@ export async function migrationRunner(db: Low<Database>) {
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();

Loading…
Cancel
Save