chitfund/backend/test-db.js

48 lines
1.5 KiB
JavaScript

const { Sequelize } = require('sequelize');
// Common PostgreSQL passwords to try
const passwords = ['password', 'admin', 'postgres', 'root', '123456', ''];
async function testConnection(password) {
const sequelize = new Sequelize('postgres', 'postgres', password, {
host: 'localhost',
port: 5432,
dialect: 'postgres',
logging: false
});
try {
await sequelize.authenticate();
console.log(`✅ SUCCESS with password: "${password}"`);
await sequelize.close();
return password;
} catch (error) {
console.log(`❌ Failed with password: "${password}" - ${error.message}`);
await sequelize.close();
return null;
}
}
async function main() {
console.log('🔍 Testing PostgreSQL connection with common passwords...\n');
for (const password of passwords) {
const result = await testConnection(password);
if (result) {
console.log(`\n🎉 Found working password: "${result}"`);
console.log('💡 Update your .env file with this password:');
console.log(` DB_PASSWORD=${result}`);
console.log(` DATABASE_URL=postgresql://postgres:${result}@localhost:5432/luckychit`);
return;
}
}
console.log('\n❌ No working password found.');
console.log('💡 Please check:');
console.log(' 1. Is PostgreSQL running?');
console.log(' 2. What is the password for user "postgres"?');
console.log(' 3. Try connecting manually with: psql -U postgres');
}
main().catch(console.error);