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;
if (shouldSync) {
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 });
console.log('✅ Database models synchronized');
} else {
@ -147,12 +150,15 @@ const startServer = async () => {
console.log(`🔔 Notifications: http://localhost:${PORT}/api/notifications`);
});
} catch (error) {
console.error('❌ Database connection failed:', error.message);
console.log('💡 Please ensure PostgreSQL is running and the database credentials are correct.');
console.log('💡 You can also try:');
console.log(' 1. Check if PostgreSQL service is running');
console.log(' 2. Verify database credentials in .env file');
console.log(' 3. Create the database: CREATE DATABASE luckychit;');
const d = sequelize.getDialect();
console.error('❌ Server startup failed:', error.message);
if (error.errors) console.error(error.errors.map((e) => e.message).join('; '));
if (d === 'sqlite') {
console.log('💡 SQLite: check SQLITE_STORAGE path, file permissions, and avoid sync alter with bad data.');
} 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);
}
};