const { Pool } = require('pg');
const dotenv = require('dotenv');

dotenv.config();

const pool = new Pool({
    user: process.env.DB_USER,
    host: process.env.DB_HOST,
    database: process.env.DB_NAME,
    password: process.env.DB_PASSWORD,
    port: process.env.DB_PORT,
});

pool.query('ALTER TABLE bookings ADD COLUMN IF NOT EXISTS payment_history TEXT;')
    .then(() => pool.query('ALTER TABLE bookings ADD COLUMN IF NOT EXISTS trip_package VARCHAR(50);'))
    .then(() => console.log('Database migrations completed: bookings columns checked.'))
    .catch(err => console.error('Database migration error:', err));

module.exports = {
    query: (text, params) => pool.query(text, params),
    pool
};
