mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-14 01:50:39 +09:00
Harden embedded postgres adoption on startup
This commit is contained in:
parent
8d5af56fc5
commit
88bf1b23a3
4 changed files with 29 additions and 22 deletions
|
|
@ -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}`,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue