| 10 | } |
| 11 | |
| 12 | function readMigrationFiles({ journal, migrations }: MigrationConfig): MigrationMeta[] { |
| 13 | const migrationQueries: MigrationMeta[] = []; |
| 14 | |
| 15 | for (const journalEntry of journal.entries) { |
| 16 | const query = migrations[`m${journalEntry.idx.toString().padStart(4, '0')}`]; |
| 17 | |
| 18 | if (!query) { |
| 19 | throw new Error(`Missing migration: ${journalEntry.tag}`); |
| 20 | } |
| 21 | |
| 22 | try { |
| 23 | const result = query.split('--> statement-breakpoint').map((it) => { |
| 24 | return it; |
| 25 | }); |
| 26 | |
| 27 | migrationQueries.push({ |
| 28 | sql: result, |
| 29 | bps: journalEntry.breakpoints, |
| 30 | folderMillis: journalEntry.when, |
| 31 | hash: '', |
| 32 | }); |
| 33 | } catch { |
| 34 | throw new Error(`Failed to parse migration: ${journalEntry.tag}`); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | return migrationQueries; |
| 39 | } |
| 40 | |
| 41 | export async function migrate< |
| 42 | TSchema extends Record<string, unknown>, |