| 1 | import path from "node:path"; |
| 2 | import { setTimeout as |
| 3 | import { fileURLToPath } |
| 4 | import { migrate } |
| 5 | |
| 6 | import { createDatabase } |
| 7 | import { seedBuiltInRows } |
| 8 | |
| 9 | // Drizzle runs each migration batch in one transaction, so a failed attempt leaves nothing half-applied to retry over. |
| 10 | const MAX_RETRIES = 3 |
| 11 | |
| 12 | async function main() |
| 13 | const migrationsFolder = |
| 14 | path.dirname(fileURLToPath |
| 15 | "..", |
| 16 | "drizzle", |
| 17 | ); |
| 18 | |
| 19 | const { db, |
| 20 | |
| 21 | try { |
| 22 | for (let attempt |
| 23 | try { |
| 24 | await migrate(db |
| 25 | break; |
| 26 | } catch (error) |
| 27 | if (attempt >= |
| 28 | const delay = |
| 29 | console.warn( |
| 30 | `Migration failed, retry ${attempt + |
| 31 | ); |
| 32 | await sleep(delay |
| 33 | } |
| 34 | } |
| 35 | console.log(`Migrations applied from |
| 36 | await seedBuiltInRows(db |
| 37 | } finally { |
| 38 | await pool.end |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | await main(); |