Fix embedded-postgres PID file written before initialization

The PID file was written to the database directory before
`pg.initialise()`, which prevented initialization from succeeding.
Moved the PID file write to just after initialization but before
starting the database.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
This commit is contained in:
Patrik Oldsberg
2026-04-08 17:04:36 +02:00
parent 5b1ba4ee3e
commit f1b493f6bd
2 changed files with 6 additions and 2 deletions
@@ -0,0 +1,5 @@
---
'@backstage/cli-module-build': patch
---
Fixed the embedded-postgres PID file being written before database initialization, which prevented the database from initializing successfully.
@@ -78,8 +78,6 @@ export async function startEmbeddedDb() {
const port = await getPortPromise();
const tmpDir = await fs.mkdtemp(resolvePath(os.tmpdir(), TEMP_DIR_PREFIX));
await fs.writeFile(resolvePath(tmpDir, PID_FILE), String(process.pid));
const pg = new EmbeddedPostgres({
databaseDir: tmpDir,
user,
@@ -94,6 +92,7 @@ export async function startEmbeddedDb() {
try {
await pg.initialise();
await fs.writeFile(resolvePath(tmpDir, PID_FILE), String(process.pid));
await pg.start();
} catch (error) {
await pg.stop().catch(() => {});