()
| 47 | } |
| 48 | |
| 49 | async run(): Promise<{ executed: number; currentVersion: number }> { |
| 50 | const currentVersion = this.getCurrentVersion() |
| 51 | const pending = this.migrations.filter((m) => m.version > currentVersion) |
| 52 | |
| 53 | if (pending.length === 0) { |
| 54 | return { executed: 0, currentVersion } |
| 55 | } |
| 56 | |
| 57 | this.context.logger.info('Migration', `${pending.length} pending migration(s), current version: ${currentVersion}`) |
| 58 | |
| 59 | let lastVersion = currentVersion |
| 60 | let executed = 0 |
| 61 | |
| 62 | for (const migration of pending) { |
| 63 | this.context.logger.info('Migration', `Running: v${lastVersion}→v${migration.version} ${migration.name}`) |
| 64 | try { |
| 65 | await migration.up(this.context) |
| 66 | lastVersion = migration.version |
| 67 | this.writeVersion(lastVersion) |
| 68 | executed++ |
| 69 | this.context.logger.info('Migration', `Completed: ${migration.name}`) |
| 70 | } catch (err) { |
| 71 | this.context.logger.error('Migration', `Failed: ${migration.name}`, err) |
| 72 | break |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | return { executed, currentVersion: lastVersion } |
| 77 | } |
| 78 | } |
no test coverage detected