fix: harden DEV runtime migration transactions
This commit is contained in:
@@ -250,7 +250,14 @@ async function verifyRuntimeReadiness(report, env, options) {
|
||||
queryClient: options.queryClient,
|
||||
pgModuleLoader: options.pgModuleLoader
|
||||
});
|
||||
const runtime = await runtimeStore.readiness();
|
||||
let runtime;
|
||||
try {
|
||||
runtime = await runtimeStore.readiness();
|
||||
} finally {
|
||||
if (!options.queryClient && typeof runtimeStore.pool?.end === "function") {
|
||||
await runtimeStore.pool.end();
|
||||
}
|
||||
}
|
||||
report.runtime = summarizeRuntime(runtime);
|
||||
report.actions.readinessVerified = runtime.ready === true;
|
||||
report.gates = gatesFromRuntime(runtime);
|
||||
@@ -277,11 +284,9 @@ async function applyMigration(report, sql, env, options) {
|
||||
if (options.queryClient) {
|
||||
client = options.queryClient;
|
||||
} else {
|
||||
const pool = await createPgPool(env, options);
|
||||
client = pool;
|
||||
closeClient = async () => {
|
||||
await pool.end();
|
||||
};
|
||||
const migrationClient = await createMigrationClient(env, options);
|
||||
client = migrationClient.client;
|
||||
closeClient = migrationClient.close;
|
||||
}
|
||||
await client.query("BEGIN");
|
||||
await client.query(sql);
|
||||
@@ -300,6 +305,27 @@ async function applyMigration(report, sql, env, options) {
|
||||
}
|
||||
}
|
||||
|
||||
async function createMigrationClient(env, options) {
|
||||
const pool = await createPgPool(env, options);
|
||||
let client;
|
||||
try {
|
||||
client = await pool.connect();
|
||||
} catch (error) {
|
||||
await pool.end();
|
||||
throw error;
|
||||
}
|
||||
return {
|
||||
client,
|
||||
close: async () => {
|
||||
try {
|
||||
client.release();
|
||||
} finally {
|
||||
await pool.end();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function createPgPool(env, options) {
|
||||
let pg;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user