mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-21 09:38:01 +02:00
35 lines
890 B
TypeScript
35 lines
890 B
TypeScript
import BaseService from './BaseService';
|
|
import Migration from '../models/Migration';
|
|
|
|
export default class MigrationService extends BaseService {
|
|
|
|
private static instance_: MigrationService;
|
|
|
|
public static instance() {
|
|
if (this.instance_) return this.instance_;
|
|
this.instance_ = new MigrationService();
|
|
return this.instance_;
|
|
}
|
|
|
|
public async runScript(num: number) {
|
|
const script = Migration.script(num);
|
|
await script.exec();
|
|
}
|
|
|
|
public 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, { sourceDescription: 'MigrationService' });
|
|
} catch (error) {
|
|
this.logger().error(`Cannot run migration: ${migration.number}`, error);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|