Harden embedded postgres adoption on startup
This commit is contained in:
@@ -10,6 +10,7 @@ import { and, eq } from "drizzle-orm";
|
||||
import {
|
||||
createDb,
|
||||
ensurePostgresDatabase,
|
||||
getPostgresDataDirectory,
|
||||
inspectMigrations,
|
||||
applyPendingMigrations,
|
||||
reconcilePendingMigrationHistory,
|
||||
@@ -322,6 +323,13 @@ export async function startServer(): Promise<StartedServer> {
|
||||
} else {
|
||||
const configuredAdminConnectionString = `postgres://paperclip:paperclip@127.0.0.1:${configuredPort}/postgres`;
|
||||
try {
|
||||
const actualDataDir = await getPostgresDataDirectory(configuredAdminConnectionString);
|
||||
if (
|
||||
typeof actualDataDir !== "string" ||
|
||||
resolve(actualDataDir) !== resolve(dataDir)
|
||||
) {
|
||||
throw new Error("reachable postgres does not use the expected embedded data directory");
|
||||
}
|
||||
await ensurePostgresDatabase(configuredAdminConnectionString, "paperclip");
|
||||
logger.warn(
|
||||
`Embedded PostgreSQL appears to already be reachable without a pid file; reusing existing server on configured port ${configuredPort}`,
|
||||
|
||||
Reference in New Issue
Block a user