Files
paperclip/cli/src/prompts/database.ts
Forgotten cc24722090 Replace PGlite with embedded-postgres and add startup banner
Switch from PGlite (WebAssembly) to embedded-postgres for zero-config
local development — provides a real PostgreSQL server with full
compatibility. Add startup banner with config summary on server boot.
Improve server bootstrap with auto port detection, database creation,
and migration on startup. Update DATABASE.md, DEVELOPING.md, and
SPEC-implementation.md to reflect the change. Update CLI database
check and prompts. Simplify OnboardingWizard database options.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 11:45:43 -06:00

73 lines
2.1 KiB
TypeScript

import * as p from "@clack/prompts";
import type { DatabaseConfig } from "../config/schema.js";
export async function promptDatabase(): Promise<DatabaseConfig> {
const mode = await p.select({
message: "Database mode",
options: [
{ value: "embedded-postgres" as const, label: "Embedded PostgreSQL (managed locally)", hint: "recommended" },
{ value: "postgres" as const, label: "PostgreSQL (external server)" },
],
});
if (p.isCancel(mode)) {
p.cancel("Setup cancelled.");
process.exit(0);
}
if (mode === "postgres") {
const connectionString = await p.text({
message: "PostgreSQL connection string",
placeholder: "postgres://user:pass@localhost:5432/paperclip",
validate: (val) => {
if (!val) return "Connection string is required for PostgreSQL mode";
if (!val.startsWith("postgres")) return "Must be a postgres:// or postgresql:// URL";
},
});
if (p.isCancel(connectionString)) {
p.cancel("Setup cancelled.");
process.exit(0);
}
return {
mode: "postgres",
connectionString,
embeddedPostgresDataDir: "./data/embedded-postgres",
embeddedPostgresPort: 54329,
};
}
const embeddedPostgresDataDir = await p.text({
message: "Embedded PostgreSQL data directory",
defaultValue: "./data/embedded-postgres",
placeholder: "./data/embedded-postgres",
});
if (p.isCancel(embeddedPostgresDataDir)) {
p.cancel("Setup cancelled.");
process.exit(0);
}
const embeddedPostgresPort = await p.text({
message: "Embedded PostgreSQL port",
defaultValue: "54329",
placeholder: "54329",
validate: (val) => {
const n = Number(val);
if (!Number.isInteger(n) || n < 1 || n > 65535) return "Port must be an integer between 1 and 65535";
},
});
if (p.isCancel(embeddedPostgresPort)) {
p.cancel("Setup cancelled.");
process.exit(0);
}
return {
mode: "embedded-postgres",
embeddedPostgresDataDir: embeddedPostgresDataDir || "./data/embedded-postgres",
embeddedPostgresPort: Number(embeddedPostgresPort || "54329"),
};
}