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_rental',
    password: process.env.DB_PASSWORD || 'password',
    port: process.env.DB_PORT || 5432,
});

const alterTable = async () => {
    const client = await pool.connect();
    try {
        console.log('Adding maintenance columns to cars table...');
        await client.query(`
            ALTER TABLE cars 
            ADD COLUMN IF NOT EXISTS maintenance_company VARCHAR(255),
            ADD COLUMN IF NOT EXISTS maintenance_start_date DATE,
            ADD COLUMN IF NOT EXISTS maintenance_end_date DATE;
        `);
        console.log('Columns added successfully!');
    } catch (err) {
        console.error('Error altering table:', err);
    } finally {
        client.release();
        await pool.end();
    }
};

alterTable();
