( sql: CodeMigrationSql, dryRun: boolean, body: () => Promise<T>, )
| 67 | }; |
| 68 | |
| 69 | const withMigrationLock = async <T>( |
| 70 | sql: CodeMigrationSql, |
| 71 | dryRun: boolean, |
| 72 | body: () => Promise<T>, |
| 73 | ): Promise<T> => { |
| 74 | if (dryRun) return body(); |
| 75 | |
| 76 | await sql.unsafe(`SELECT pg_advisory_lock(hashtext('${ADVISORY_LOCK_KEY}'))`); |
| 77 | try { |
| 78 | return await body(); |
| 79 | } finally { |
| 80 | await sql.unsafe(`SELECT pg_advisory_unlock(hashtext('${ADVISORY_LOCK_KEY}'))`); |
| 81 | } |
| 82 | }; |
| 83 | |
| 84 | export const runCodeMigrations = async ( |
| 85 | sql: CodeMigrationSql, |
no test coverage detected