1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/packages/lib/services/MigrationService.js

38 lines
842 B
JavaScript
Raw Normal View History

2020-11-05 18:58:23 +02:00
const BaseService = require('./BaseService').default;
const Migration = require('../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) {
2019-09-19 23:51:18 +02:00
this.logger().info(`Running migration: ${migration.number}`);
try {
await this.runScript(migration.number);
await Migration.delete(migration.id);
} catch (error) {
2019-09-19 23:51:18 +02:00
this.logger().error(`Cannot run migration: ${migration.number}`, error);
break;
}
}
}
}
2019-07-29 15:43:53 +02:00
module.exports = MigrationService;