diff --git a/server/routes/branding.js b/server/routes/branding.js index f50c20a..56be9ff 100644 --- a/server/routes/branding.js +++ b/server/routes/branding.js @@ -50,12 +50,11 @@ async function getSetting(key) { // Helper: set setting in DB async function setSetting(key, value) { const db = getDb(); - // Upsert - const existing = await db.get('SELECT key FROM settings WHERE key = ?', [key]); - if (existing) { - await db.run('UPDATE settings SET value = ?, updated_at = CURRENT_TIMESTAMP WHERE key = ?', [value, key]); - } else { - await db.run('INSERT INTO settings (key, value) VALUES (?, ?)', [key, value]); + // Try update first, then insert if nothing was updated + const result = await db.run('UPDATE settings SET value = ?, updated_at = CURRENT_TIMESTAMP WHERE key = ?', [value, key]); + if (result.changes === 0) { + // Use INSERT with a dummy RETURNING to satisfy PG adapter, or just use exec-style + await db.run('INSERT INTO settings (key, value) VALUES (?, ?) RETURNING key', [key, value]); } }