Add auto-migration for OCR settings column
🔄 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.
This commit is contained in:
parent
f441d1aee5
commit
bf569360cf
1 changed files with 17 additions and 0 deletions
|
|
@ -30,6 +30,23 @@ export default async function handler(req, res) {
|
||||||
try {
|
try {
|
||||||
const user = verifyAuth(req);
|
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') {
|
if (req.method === 'GET') {
|
||||||
// Get user preferences
|
// Get user preferences
|
||||||
const result = await client.query(`
|
const result = await client.query(`
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue