cli: address review feedback for embedded-postgres
- Close embedded DB on shutdown to avoid leaking the Postgres process and temp directory - Use fs.remove instead of deprecated fs.rmdir with recursive option - Guard against absolute config paths in readDatabaseClient - Forward embedded-postgres error logs to console.error Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com> Made-with: Cursor
This commit is contained in:
@@ -66,12 +66,14 @@ export async function runBackend(options: RunBackendOptions) {
|
||||
|
||||
const extraEnv: Record<string, string> = {};
|
||||
|
||||
let embeddedDb: Awaited<ReturnType<typeof startEmbeddedDb>> | undefined;
|
||||
|
||||
const dbClient = await readDatabaseClient(options.configPaths);
|
||||
if (dbClient === 'embedded-postgres') {
|
||||
const db = await startEmbeddedDb();
|
||||
embeddedDb = await startEmbeddedDb();
|
||||
extraEnv.APP_CONFIG_backend_database = JSON.stringify({
|
||||
client: 'pg',
|
||||
connection: db.connection,
|
||||
connection: embeddedDb.connection,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -205,6 +207,7 @@ export async function runBackend(options: RunBackendOptions) {
|
||||
});
|
||||
}
|
||||
|
||||
await embeddedDb?.close();
|
||||
resolveExitPromise();
|
||||
}
|
||||
|
||||
@@ -224,7 +227,7 @@ async function readDatabaseClient(
|
||||
allowMissingDefaultConfig: true,
|
||||
argv: (configPaths ?? []).flatMap(p => [
|
||||
'--config',
|
||||
resolvePath(rootDir, p),
|
||||
isAbsolutePath(p) ? p : resolvePath(rootDir, p),
|
||||
]),
|
||||
});
|
||||
|
||||
|
||||
@@ -45,7 +45,9 @@ export async function startEmbeddedDb() {
|
||||
password,
|
||||
port,
|
||||
persistent: false,
|
||||
onError() {},
|
||||
onError(messageOrError) {
|
||||
console.error(`[embedded-postgres]`, messageOrError);
|
||||
},
|
||||
onLog() {},
|
||||
});
|
||||
|
||||
@@ -64,7 +66,7 @@ export async function startEmbeddedDb() {
|
||||
},
|
||||
async close() {
|
||||
await pg.stop();
|
||||
await fs.rmdir(tmpDir, { recursive: true, maxRetries: 3 });
|
||||
await fs.remove(tmpDir);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user