()
| 63 | * across {@link MAX_CONNECT_ATTEMPTS} attempts. |
| 64 | */ |
| 65 | export async function assertSchemaCompatibility(): Promise<void> { |
| 66 | let lastError: unknown |
| 67 | |
| 68 | for (let attempt = 1; attempt <= MAX_CONNECT_ATTEMPTS; attempt++) { |
| 69 | try { |
| 70 | await db.select().from(workflow).limit(1) |
| 71 | logger.info('Schema-compatibility check passed') |
| 72 | return |
| 73 | } catch (error) { |
| 74 | lastError = error |
| 75 | |
| 76 | if (isSchemaMismatch(error)) { |
| 77 | throw new Error( |
| 78 | `Deployed image is incompatible with the live database schema: ${getErrorMessage(error)}` |
| 79 | ) |
| 80 | } |
| 81 | |
| 82 | if (attempt === MAX_CONNECT_ATTEMPTS) { |
| 83 | break |
| 84 | } |
| 85 | |
| 86 | const delay = backoffWithJitter(attempt, null) |
| 87 | logger.warn( |
| 88 | `Schema-compatibility check could not reach the database (attempt ${attempt}/${MAX_CONNECT_ATTEMPTS}), retrying in ${Math.round(delay)}ms`, |
| 89 | getErrorMessage(error) |
| 90 | ) |
| 91 | await sleep(delay) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | throw new Error( |
| 96 | `Schema-compatibility check failed after ${MAX_CONNECT_ATTEMPTS} attempts — database unreachable: ${getErrorMessage(lastError)}` |
| 97 | ) |
| 98 | } |
no test coverage detected