<?php
require_once __DIR__ . '/config.php';

try {
    $db = db();
    
    // Check current column types for 'type' and 'status' in 'planets' table
    $stmt = $db->query("DESCRIBE planets");
    $columns = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo "Current schema for 'planets' table:\n";
    foreach ($columns as $column) {
        if ($column['Field'] === 'type' || $column['Field'] === 'status') {
            echo "- {$column['Field']}: {$column['Type']}\n";
        }
    }

    echo "\nConverting 'type' and 'status' columns to VARCHAR(50) to allow dynamic values...\n";

    // Convert 'type' to VARCHAR(50)
    $db->exec("ALTER TABLE planets MODIFY COLUMN type VARCHAR(50) NOT NULL DEFAULT 'planet'");
    echo "Column 'type' converted successfully.\n";

    // Convert 'status' to VARCHAR(50)
    $db->exec("ALTER TABLE planets MODIFY COLUMN status VARCHAR(50) NOT NULL DEFAULT 'stable'");
    echo "Column 'status' converted successfully.\n";

    echo "\nMigration completed successfully. New types and statuses will now be accepted.\n";

} catch (PDOException $e) {
    echo "Error during migration: " . $e->getMessage() . "\n";
    exit(1);
}
?>