Fix settings: catch DB errors at build time, return defaults

getSettings() and getSetting() now fall back to defaults when the
database is unavailable (e.g., during Docker image build).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-08 12:23:26 +05:00
parent e77588deb8
commit 58a61d6f04
+9
View File
@@ -44,17 +44,26 @@ export type Settings = Record<SettingsKey, string>;
// ── Getters ───────────────────────────────────────────────────────────────────
export async function getSettings(): Promise<Settings> {
try {
const rows = await prisma.settings.findMany();
const stored: Record<string, string> = {};
for (const row of rows) stored[row.key] = row.value;
return Object.fromEntries(
Object.entries(SETTINGS_DEFAULTS).map(([k, v]) => [k, stored[k] ?? v])
) as Settings;
} catch {
// DB unavailable at build time — return defaults
return { ...SETTINGS_DEFAULTS } as Settings;
}
}
export async function getSetting(key: SettingsKey): Promise<string> {
try {
const row = await prisma.settings.findUnique({ where: { key } });
return row?.value ?? SETTINGS_DEFAULTS[key];
} catch {
return SETTINGS_DEFAULTS[key];
}
}
// ── Convenience helpers ───────────────────────────────────────────────────────