import { pool } from "./config/db.js";

async function run() {
  const connection = await pool.getConnection();
  try {
    console.log("Checking if 'descripcion_item' column exists in 'order_items'...");
    const [columns] = await connection.query(`
      SELECT COLUMN_NAME 
      FROM INFORMATION_SCHEMA.COLUMNS 
      WHERE TABLE_SCHEMA = 'laundry_app' 
        AND TABLE_NAME = 'order_items' 
        AND COLUMN_NAME = 'descripcion_item'
    `);
    
    if (columns.length === 0) {
      console.log("Adding 'descripcion_item' column to 'order_items' table...");
      await connection.query(`
        ALTER TABLE order_items ADD COLUMN descripcion_item VARCHAR(255) NULL
      `);
      console.log("Column added successfully!");
    } else {
      console.log("Column 'descripcion_item' already exists.");
    }
    process.exit(0);
  } catch (err) {
    console.error("Migration failed:", err);
    process.exit(1);
  } finally {
    connection.release();
  }
}

run();
