From bf569360cf44498e9ab049d350bbc5a7bd4a0a03 Mon Sep 17 00:00:00 2001 From: Randall Stillwell Date: Tue, 22 Jul 2025 10:57:20 -0500 Subject: [PATCH] Add auto-migration for OCR settings column MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🔄 Database Auto-Migration: - Add automatic schema update in user preferences API - Ensures ocr_settings column exists when first accessed - Uses ADD COLUMN IF NOT EXISTS for safe migration - Handles case where column might already exist - No need for separate migration endpoint This ensures the settings page will work immediately after deployment without requiring manual database updates. --- api/user/preferences.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/api/user/preferences.js b/api/user/preferences.js index 2ec0fa6..2a4ec01 100644 --- a/api/user/preferences.js +++ b/api/user/preferences.js @@ -30,6 +30,23 @@ export default async function handler(req, res) { try { const user = verifyAuth(req); + // Ensure ocr_settings column exists (auto-migration) + try { + await client.query(` + ALTER TABLE user_preferences + ADD COLUMN IF NOT EXISTS ocr_settings JSONB DEFAULT '{ + "preferred_service": "openai", + "openai_api_key": "", + "ollama_url": "http://localhost:11434", + "auto_add_to_collection": false, + "confidence_threshold": 80 + }'::jsonb; + `); + } catch (error) { + // Column might already exist, ignore error + console.log('OCR settings column may already exist:', error.message); + } + if (req.method === 'GET') { // Get user preferences const result = await client.query(`