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

dotenv.config({ path: path.join(__dirname, '.env') });

const pool = new Pool({
    user: process.env.DB_USER || 'postgres',
    host: process.env.DB_HOST || 'localhost',
    database: process.env.DB_NAME || 'car',
    password: process.env.DB_PASSWORD || 'ragu@2003',
    port: process.env.DB_PORT || 5432,
});

const alterTable = async () => {
    const client = await pool.connect();
    try {
        console.log('Adding pricing columns to cars table...');
        await client.query(`
            ALTER TABLE cars 
            ADD COLUMN IF NOT EXISTS price_per_hour DECIMAL(10, 2),
            ADD COLUMN IF NOT EXISTS price_per_week DECIMAL(10, 2),
            ADD COLUMN IF NOT EXISTS price_per_month DECIMAL(10, 2);
        `);
        console.log('Pricing columns added successfully!');
    } catch (err) {
        console.error('Error altering table:', err);
    } finally {
        client.release();
        await pool.end();
    }
};

alterTable();
