fix: parse JSON string values from MariaDB in org_config loader
MariaDB returns JSON columns as strings via mysql2 driver. Added parseJsonValue() to handle both string and object values. Fixes config not loading on production (always showing defaults). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -87,6 +87,13 @@ const KEY_MAP: Record<string, keyof OrgConfig> = {
|
||||
setup_complete: 'setupComplete'
|
||||
};
|
||||
|
||||
function parseJsonValue(value: unknown): unknown {
|
||||
if (typeof value === 'string') {
|
||||
try { return JSON.parse(value); } catch { return value; }
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function parseOrgConfig(rows: { key: string; value: unknown }[]): OrgConfig {
|
||||
const config = structuredClone(DEFAULTS);
|
||||
|
||||
@@ -94,12 +101,14 @@ export function parseOrgConfig(rows: { key: string; value: unknown }[]): OrgConf
|
||||
const configKey = KEY_MAP[row.key];
|
||||
if (!configKey) continue;
|
||||
|
||||
const parsed = parseJsonValue(row.value);
|
||||
|
||||
if (configKey === 'setupComplete') {
|
||||
config.setupComplete = Boolean(row.value);
|
||||
config.setupComplete = Boolean(parsed);
|
||||
} else {
|
||||
config[configKey] = {
|
||||
...config[configKey],
|
||||
...(row.value as Record<string, unknown>)
|
||||
...(parsed as Record<string, unknown>)
|
||||
} as any;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user