1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00
joplin/ReactNativeClient/lib/services/MigrationService.js
2019-09-19 22:51:18 +01:00

38 lines
846 B
JavaScript

const BaseService = require('lib/services/BaseService');
const Migration = require('lib/models/Migration');
class MigrationService extends BaseService {
constructor() {
super();
}
static instance() {
if (this.instance_) return this.instance_;
this.instance_ = new MigrationService();
return this.instance_;
}
async runScript(num) {
const script = Migration.script(num);
await script.exec();
}
async run() {
const migrations = await Migration.migrationsToDo();
for (const migration of migrations) {
this.logger().info(`Running migration: ${migration.number}`);
try {
await this.runScript(migration.number);
await Migration.delete(migration.id);
} catch (error) {
this.logger().error(`Cannot run migration: ${migration.number}`, error);
break;
}
}
}
}
module.exports = MigrationService;