## What was done: ✅ Fixed Firebase Admin initialization to use default credentials for Firebase Functions ✅ Updated frontend to use correct Firebase Functions URL (was using Cloud Run URL) ✅ Added comprehensive debugging to authentication middleware ✅ Added debugging to file upload middleware and CORS handling ✅ Added debug buttons to frontend for troubleshooting authentication ✅ Enhanced error handling and logging throughout the stack ## Current issues: ❌ Document upload still returns 400 Bad Request despite authentication working ❌ GET requests work fine (200 OK) but POST upload requests fail ❌ Frontend authentication is working correctly (valid JWT tokens) ❌ Backend authentication middleware is working (rejects invalid tokens) ❌ CORS is configured correctly and allowing requests ## Root cause analysis: - Authentication is NOT the issue (tokens are valid, GET requests work) - The problem appears to be in the file upload handling or multer configuration - Request reaches the server but fails during upload processing - Need to identify exactly where in the upload pipeline the failure occurs ## TODO next steps: 1. 🔍 Check Firebase Functions logs after next upload attempt to see debugging output 2. 🔍 Verify if request reaches upload middleware (look for '�� Upload middleware called' logs) 3. 🔍 Check if file validation is triggered (look for '🔍 File filter called' logs) 4. 🔍 Identify specific error in upload pipeline (multer, file processing, etc.) 5. 🔍 Test with smaller file or different file type to isolate issue 6. 🔍 Check if issue is with Firebase Functions file size limits or timeout 7. 🔍 Verify multer configuration and file handling in Firebase Functions environment ## Technical details: - Frontend: https://cim-summarizer.web.app - Backend: https://us-central1-cim-summarizer.cloudfunctions.net/api - Authentication: Firebase Auth with JWT tokens (working correctly) - File upload: Multer with memory storage for immediate GCS upload - Debug buttons available in production frontend for troubleshooting
77 lines
2.4 KiB
JavaScript
77 lines
2.4 KiB
JavaScript
const { Pool } = require('pg');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// Production DATABASE_URL from deployed function
|
|
const DATABASE_URL = 'postgresql://postgres.gzoclmbqmgmpuhufbnhy:postgres@aws-0-us-east-1.pooler.supabase.com:6543/postgres';
|
|
|
|
const pool = new Pool({
|
|
connectionString: DATABASE_URL,
|
|
max: 1,
|
|
idleTimeoutMillis: 30000,
|
|
connectionTimeoutMillis: 10000,
|
|
});
|
|
|
|
async function runMigrations() {
|
|
console.log('Starting production database migrations...');
|
|
console.log('Using DATABASE_URL:', DATABASE_URL.replace(/:[^:@]*@/, ':****@')); // Hide password
|
|
|
|
try {
|
|
// Test connection first
|
|
const client = await pool.connect();
|
|
console.log('✅ Database connection successful');
|
|
|
|
// Create migrations table if it doesn't exist
|
|
await client.query(`
|
|
CREATE TABLE IF NOT EXISTS migrations (
|
|
id VARCHAR(255) PRIMARY KEY,
|
|
name VARCHAR(255) NOT NULL,
|
|
executed_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
`);
|
|
console.log('✅ Migrations table created or already exists');
|
|
|
|
// Get migration files
|
|
const migrationsDir = path.join(__dirname, '../src/models/migrations');
|
|
const files = fs.readdirSync(migrationsDir)
|
|
.filter(file => file.endsWith('.sql'))
|
|
.sort();
|
|
|
|
console.log(`Found ${files.length} migration files`);
|
|
|
|
for (const file of files) {
|
|
const migrationId = file.replace('.sql', '');
|
|
|
|
// Check if migration already executed
|
|
const { rows } = await client.query('SELECT id FROM migrations WHERE id = $1', [migrationId]);
|
|
|
|
if (rows.length > 0) {
|
|
console.log(`⏭️ Migration ${migrationId} already executed, skipping`);
|
|
continue;
|
|
}
|
|
|
|
// Load and execute migration
|
|
const filePath = path.join(migrationsDir, file);
|
|
const sql = fs.readFileSync(filePath, 'utf-8');
|
|
|
|
console.log(`🔄 Executing migration: ${migrationId}`);
|
|
await client.query(sql);
|
|
|
|
// Mark as executed
|
|
await client.query('INSERT INTO migrations (id, name) VALUES ($1, $2)', [migrationId, file]);
|
|
console.log(`✅ Migration ${migrationId} completed`);
|
|
}
|
|
|
|
client.release();
|
|
await pool.end();
|
|
|
|
console.log('🎉 All production migrations completed successfully!');
|
|
|
|
} catch (error) {
|
|
console.error('❌ Migration failed:', error.message);
|
|
console.error('Error details:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
runMigrations();
|