65 lines
1.7 KiB
JavaScript
65 lines
1.7 KiB
JavaScript
|
|
const { Pool } = require('pg');
|
||
|
|
|
||
|
|
const pool = new Pool({
|
||
|
|
connectionString: process.env.DATABASE_URL,
|
||
|
|
ssl: process.env.NODE_ENV === 'production' ? { rejectUnauthorized: false } : false,
|
||
|
|
});
|
||
|
|
|
||
|
|
export default async function handler(req, res) {
|
||
|
|
if (req.method !== 'POST') {
|
||
|
|
return res.status(405).json({ error: 'Method not allowed' });
|
||
|
|
}
|
||
|
|
|
||
|
|
const client = await pool.connect();
|
||
|
|
|
||
|
|
try {
|
||
|
|
console.log('Updating user_preferences schema to add OCR settings...');
|
||
|
|
|
||
|
|
// Check if ocr_settings column already exists
|
||
|
|
const columnCheck = await client.query(`
|
||
|
|
SELECT EXISTS (
|
||
|
|
SELECT FROM information_schema.columns
|
||
|
|
WHERE table_schema = 'public'
|
||
|
|
AND table_name = 'user_preferences'
|
||
|
|
AND column_name = 'ocr_settings'
|
||
|
|
);
|
||
|
|
`);
|
||
|
|
|
||
|
|
if (columnCheck.rows[0].exists) {
|
||
|
|
return res.status(200).json({
|
||
|
|
success: true,
|
||
|
|
message: 'OCR settings column already exists',
|
||
|
|
already_updated: true
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
// Add ocr_settings column
|
||
|
|
await client.query(`
|
||
|
|
ALTER TABLE user_preferences
|
||
|
|
ADD COLUMN ocr_settings JSONB DEFAULT '{
|
||
|
|
"preferred_service": "openai",
|
||
|
|
"openai_api_key": "",
|
||
|
|
"ollama_url": "http://localhost:11434",
|
||
|
|
"auto_add_to_collection": false,
|
||
|
|
"confidence_threshold": 80
|
||
|
|
}'::jsonb;
|
||
|
|
`);
|
||
|
|
|
||
|
|
console.log('✅ OCR settings column added to user_preferences table');
|
||
|
|
|
||
|
|
res.status(200).json({
|
||
|
|
success: true,
|
||
|
|
message: 'User preferences schema updated successfully with OCR settings'
|
||
|
|
});
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
console.error('Schema update failed:', error);
|
||
|
|
res.status(500).json({
|
||
|
|
success: false,
|
||
|
|
error: 'Schema update failed',
|
||
|
|
details: error.message
|
||
|
|
});
|
||
|
|
} finally {
|
||
|
|
client.release();
|
||
|
|
}
|
||
|
|
}
|