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