<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Include standard DB configuration
require_once dirname(__DIR__) . '/config/db.php';

if (!isset($conn) || $conn->connect_error) {
    die("Database connection failed.");
}

echo "Connected successfully to DB!<br>";

// Add column sort_order if not exists
$res = $conn->query("SHOW COLUMNS FROM packages LIKE 'sort_order'");
if ($res) {
    if ($res->num_rows == 0) {
        if ($conn->query("ALTER TABLE packages ADD COLUMN sort_order INT DEFAULT 0")) {
            echo "Successfully added 'sort_order' column to 'packages' table.<br>";
        } else {
            echo "Error adding column: " . $conn->error . "<br>";
        }
    } else {
        echo "'sort_order' column already exists.<br>";
    }
} else {
    echo "Error querying table schema: " . $conn->error . "<br>";
}
