This commit is contained in:
commit
59bb5a38a3
132 files changed
+19435
No files matched your search
@@ -0,0 +1,49 @@
|
||||
// Lokale PostgreSQL-Instanz fuer die Entwicklung ohne Docker.
|
||||
//
|
||||
// pnpm db:dev startet PostgreSQL auf Port 54329 (Strg+C beendet)
|
||||
//
|
||||
// Mit Docker stattdessen: docker compose up -d db (siehe docker-compose.yml).
|
||||
//
|
||||
// Das Datenverzeichnis liegt bewusst NICHT im Projektordner: dieser liegt
|
||||
// hier in einem OneDrive-synchronisierten Verzeichnis, und ein
|
||||
// PostgreSQL-Datenverzeichnis in einer Cloud-Synchronisierung fuehrt zu
|
||||
// gesperrten oder beschaedigten Dateien.
|
||||
import EmbeddedPostgres from "embedded-postgres";
|
||||
import { existsSync } from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
const baseDir = process.env.LOCALAPPDATA ?? path.join(os.homedir(), ".local", "share");
|
||||
const databaseDir = path.join(baseDir, "artista-modelcamp", "dev-db");
|
||||
const port = Number(process.env.DEV_DB_PORT ?? 54329);
|
||||
|
||||
const pg = new EmbeddedPostgres({
|
||||
databaseDir,
|
||||
user: "artista",
|
||||
password: "artista-dev",
|
||||
port,
|
||||
persistent: true,
|
||||
onLog: () => {},
|
||||
});
|
||||
|
||||
if (!existsSync(path.join(databaseDir, "PG_VERSION"))) {
|
||||
await pg.initialise();
|
||||
}
|
||||
await pg.start();
|
||||
try {
|
||||
await pg.createDatabase("artista");
|
||||
} catch {
|
||||
// existiert bereits
|
||||
}
|
||||
|
||||
console.log(`PostgreSQL laeuft: postgresql://artista:artista-dev@localhost:${port}/artista`);
|
||||
console.log(`Daten: ${databaseDir}`);
|
||||
|
||||
const shutdown = async () => {
|
||||
await pg.stop();
|
||||
process.exit(0);
|
||||
};
|
||||
process.on("SIGINT", shutdown);
|
||||
process.on("SIGTERM", shutdown);
|
||||
// Prozess am Leben halten.
|
||||
setInterval(() => {}, 1 << 30);
|
||||
Reference in new issue
Block a user