diff --git a/backend/create-db.js b/backend/create-db.js index 23e3c87..2e6f84c 100644 --- a/backend/create-db.js +++ b/backend/create-db.js @@ -1,16 +1,24 @@ const { Sequelize } = require('sequelize'); +require('dotenv').config(); async function createDatabase() { // Connect to default postgres database first - const sequelize = new Sequelize('postgres', 'postgres', 'postgres', { - host: 'localhost', - port: 5432, + // Use credentials from .env or defaults + const dbUser = process.env.DB_USER || 'postgres'; + const dbPassword = process.env.DB_PASSWORD || 'postgres'; + const dbHost = process.env.DB_HOST || 'localhost'; + const dbPort = process.env.DB_PORT || 5432; + + console.log(`🔌 Connecting to PostgreSQL at ${dbHost}:${dbPort} as user "${dbUser}"...`); + + const sequelize = new Sequelize('postgres', dbUser, dbPassword, { + host: dbHost, + port: dbPort, dialect: 'postgres', logging: false }); try { - console.log('🔌 Connecting to PostgreSQL...'); await sequelize.authenticate(); console.log('✅ Connected to PostgreSQL successfully');