You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
All: Save size of a resource to the database; and added mechanism to run non-database migrations
This commit is contained in:
37
ReactNativeClient/lib/services/MigrationService.js
Normal file
37
ReactNativeClient/lib/services/MigrationService.js
Normal file
@ -0,0 +1,37 @@
|
||||
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 run() {
|
||||
const migrations = await Migration.migrationsToDo();
|
||||
|
||||
for (const migration of migrations) {
|
||||
this.logger().info('Running migration: ' + migration.number);
|
||||
|
||||
const script = Migration.script(migration.number);
|
||||
|
||||
try {
|
||||
await script.exec();
|
||||
await Migration.delete(migration.id);
|
||||
} catch (error) {
|
||||
this.logger().error('Cannot run migration: ' + migration.number, error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = MigrationService;
|
Reference in New Issue
Block a user