MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / withMigrationLock

Function withMigrationLock

apps/cloud/scripts/code-migrations/runner.ts:69–82  ·  view source on GitHub ↗
(
  sql: CodeMigrationSql,
  dryRun: boolean,
  body: () => Promise<T>,
)

Source from the content-addressed store, hash-verified

67};
68
69const 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
84export const runCodeMigrations = async (
85 sql: CodeMigrationSql,

Callers 1

runCodeMigrationsFunction · 0.85

Calls 1

unsafeMethod · 0.80

Tested by

no test coverage detected