(db: DatabaseAdapter, migrationsList: Migration[], forceRepair = false)
| 62 | * @returns 是否执行了迁移 |
| 63 | */ |
| 64 | export function runMigrations(db: DatabaseAdapter, migrationsList: Migration[], forceRepair = false): boolean { |
| 65 | const currentVersion = getSchemaVersion(db) |
| 66 | |
| 67 | if (!forceRepair && currentVersion >= (migrationsList.at(-1)?.version ?? 0)) { |
| 68 | return false |
| 69 | } |
| 70 | |
| 71 | const pending = forceRepair ? migrationsList : migrationsList.filter((m) => m.version > currentVersion) |
| 72 | |
| 73 | if (pending.length === 0) return false |
| 74 | |
| 75 | db.transaction(() => { |
| 76 | for (const migration of pending) { |
| 77 | migration.up(db) |
| 78 | setSchemaVersion(db, migration.version) |
| 79 | } |
| 80 | }) |
| 81 | |
| 82 | return true |
| 83 | } |
no test coverage detected