
import pool from './db.js';

async function migrate() {
    try {
        console.log('Starting migration...');

        // Add columns to invoices
        try {
            await pool.query('ALTER TABLE invoices ADD COLUMN notes TEXT');
            console.log('Added notes to invoices');
        } catch (e) {
            console.log('notes already exists in invoices or error');
        }

        try {
            await pool.query('ALTER TABLE invoices ADD COLUMN items LONGTEXT');
            console.log('Added items to invoices');
        } catch (e) {
            console.log('items already exists in invoices or error');
        }

        // Add columns to quotations if missing
        try {
            await pool.query('ALTER TABLE quotations ADD COLUMN terms TEXT');
            console.log('Added terms to quotations');
        } catch (e) {
            console.log('terms already exists in quotations or error');
        }

        try {
            await pool.query('ALTER TABLE quotations ADD COLUMN items LONGTEXT');
            console.log('Added items to quotations');
        } catch (e) {
            console.log('items already exists in quotations or error');
        }

        console.log('Migration finished');
        process.exit(0);
    } catch (error) {
        console.error('Migration failed:', error);
        process.exit(1);
    }
}

migrate();
