Add secrets section to onboard, configure, and doctor commands. Doctor validates local encrypted provider key file and can auto-repair missing keys. Extract shared path resolution into path-resolver module used by database and log checks. Show secrets env vars in `paperclip env`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
68 lines
2.1 KiB
TypeScript
68 lines
2.1 KiB
TypeScript
import fs from "node:fs";
|
|
import type { PaperclipConfig } from "../config/schema.js";
|
|
import type { CheckResult } from "./index.js";
|
|
import { resolveRuntimeLikePath } from "./path-resolver.js";
|
|
|
|
export async function databaseCheck(config: PaperclipConfig, configPath?: string): Promise<CheckResult> {
|
|
if (config.database.mode === "postgres") {
|
|
if (!config.database.connectionString) {
|
|
return {
|
|
name: "Database",
|
|
status: "fail",
|
|
message: "PostgreSQL mode selected but no connection string configured",
|
|
canRepair: false,
|
|
repairHint: "Run `paperclip configure --section database`",
|
|
};
|
|
}
|
|
|
|
try {
|
|
const { createDb } = await import("@paperclip/db");
|
|
const db = createDb(config.database.connectionString);
|
|
await db.execute("SELECT 1");
|
|
return {
|
|
name: "Database",
|
|
status: "pass",
|
|
message: "PostgreSQL connection successful",
|
|
};
|
|
} catch (err) {
|
|
return {
|
|
name: "Database",
|
|
status: "fail",
|
|
message: `Cannot connect to PostgreSQL: ${err instanceof Error ? err.message : String(err)}`,
|
|
canRepair: false,
|
|
repairHint: "Check your connection string and ensure PostgreSQL is running",
|
|
};
|
|
}
|
|
}
|
|
|
|
if (config.database.mode === "embedded-postgres") {
|
|
const dataDir = resolveRuntimeLikePath(config.database.embeddedPostgresDataDir, configPath);
|
|
const reportedPath = dataDir;
|
|
if (!fs.existsSync(dataDir)) {
|
|
return {
|
|
name: "Database",
|
|
status: "warn",
|
|
message: `Embedded PostgreSQL data directory does not exist: ${reportedPath}`,
|
|
canRepair: true,
|
|
repair: () => {
|
|
fs.mkdirSync(reportedPath, { recursive: true });
|
|
},
|
|
};
|
|
}
|
|
|
|
return {
|
|
name: "Database",
|
|
status: "pass",
|
|
message: `Embedded PostgreSQL configured at ${dataDir} (port ${config.database.embeddedPostgresPort})`,
|
|
};
|
|
}
|
|
|
|
return {
|
|
name: "Database",
|
|
status: "fail",
|
|
message: `Unknown database mode: ${String(config.database.mode)}`,
|
|
canRepair: false,
|
|
repairHint: "Run `paperclip configure --section database`",
|
|
};
|
|
}
|