<?php
// Database Migration Script - Rename booking columns
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'rest_table');

// Create connection
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Check if columns already exist
$result = $conn->query("SHOW COLUMNS FROM bookings LIKE 'slot_time'");
if ($result->num_rows > 0) {
    echo "✓ Column 'slot_time' already exists. Migration already applied or in progress.\n";
    exit;
}

// Rename booking_time to slot_time
$sql1 = "ALTER TABLE bookings CHANGE COLUMN booking_time slot_time TIME NOT NULL";
if ($conn->query($sql1)) {
    echo "✓ Successfully renamed 'booking_time' to 'slot_time'\n";
} else {
    echo "✗ Error renaming booking_time: " . $conn->error . "\n";
    exit;
}

// Rename occasion to meal_type
$sql2 = "ALTER TABLE bookings CHANGE COLUMN occasion meal_type VARCHAR(50)";
if ($conn->query($sql2)) {
    echo "✓ Successfully renamed 'occasion' to 'meal_type'\n";
} else {
    echo "✗ Error renaming occasion: " . $conn->error . "\n";
    exit;
}

echo "\n✓ Migration completed successfully!\n";
$conn->close();
?>
