(db: SqliteDatabase, fromVersion: number)
| 180 | * Run all pending migrations |
| 181 | */ |
| 182 | export function runMigrations(db: SqliteDatabase, fromVersion: number): void { |
| 183 | const pending = migrations.filter((m) => m.version > fromVersion); |
| 184 | |
| 185 | if (pending.length === 0) { |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | // Sort by version |
| 190 | pending.sort((a, b) => a.version - b.version); |
| 191 | |
| 192 | // Run each migration in a transaction |
| 193 | for (const migration of pending) { |
| 194 | db.transaction(() => { |
| 195 | migration.up(db); |
| 196 | recordMigration(db, migration.version, migration.description); |
| 197 | })(); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Check if the database needs migration |
no test coverage detected