fixed login error

This commit is contained in:
Deep Koluguri 2026-04-05 16:17:37 -04:00
parent b3476834cf
commit c95aa3eff7
1 changed files with 13 additions and 7 deletions

View File

@ -126,7 +126,10 @@ const startServer = async () => {
process.env.NODE_ENV !== 'production' || autoSync || isSqlite; process.env.NODE_ENV !== 'production' || autoSync || isSqlite;
if (shouldSync) { if (shouldSync) {
console.log('🔄 Syncing database models...'); console.log('🔄 Syncing database models...');
const alter = process.env.NODE_ENV !== 'production'; // Never use alter on SQLite: Sequelize copies via *_backup tables with NOT NULL timestamps;
// migrated rows with null created_at/updated_at → INSERT fails → crash loop (PM2 502).
const alter =
process.env.NODE_ENV !== 'production' && sequelize.getDialect() !== 'sqlite';
await sequelize.sync({ alter }); await sequelize.sync({ alter });
console.log('✅ Database models synchronized'); console.log('✅ Database models synchronized');
} else { } else {
@ -147,12 +150,15 @@ const startServer = async () => {
console.log(`🔔 Notifications: http://localhost:${PORT}/api/notifications`); console.log(`🔔 Notifications: http://localhost:${PORT}/api/notifications`);
}); });
} catch (error) { } catch (error) {
console.error('❌ Database connection failed:', error.message); const d = sequelize.getDialect();
console.log('💡 Please ensure PostgreSQL is running and the database credentials are correct.'); console.error('❌ Server startup failed:', error.message);
console.log('💡 You can also try:'); if (error.errors) console.error(error.errors.map((e) => e.message).join('; '));
console.log(' 1. Check if PostgreSQL service is running'); if (d === 'sqlite') {
console.log(' 2. Verify database credentials in .env file'); console.log('💡 SQLite: check SQLITE_STORAGE path, file permissions, and avoid sync alter with bad data.');
console.log(' 3. Create the database: CREATE DATABASE luckychit;'); } else {
console.log('💡 Ensure the database is running and credentials in .env are correct.');
console.log('💡 Create the DB if needed: CREATE DATABASE luckychit;');
}
process.exit(1); process.exit(1);
} }
}; };