<?php
try {
    $pdo = new PDO('mysql:host=127.0.0.1;dbname=projects_membershipdb;charset=utf8mb4', 'root', '', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);

    // Check if media column exists in forum_topics
    $stmt = $pdo->query("SHOW COLUMNS FROM forum_topics LIKE 'media'");
    if (!$stmt->fetch()) {
        $pdo->exec("ALTER TABLE forum_topics ADD COLUMN media TEXT DEFAULT NULL AFTER body");
        echo "Added media column to forum_topics\n";
    } else {
        echo "media column already exists in forum_topics\n";
    }

    // Check if media column exists in forum_posts
    $stmt = $pdo->query("SHOW COLUMNS FROM forum_posts LIKE 'media'");
    if (!$stmt->fetch()) {
        $pdo->exec("ALTER TABLE forum_posts ADD COLUMN media TEXT DEFAULT NULL AFTER body");
        echo "Added media column to forum_posts\n";
    } else {
        echo "media column already exists in forum_posts\n";
    }

    // Check if status column exists in forum_posts
    $stmt = $pdo->query("SHOW COLUMNS FROM forum_posts LIKE 'status'");
    if (!$stmt->fetch()) {
        $pdo->exec("ALTER TABLE forum_posts ADD COLUMN status ENUM('active','deleted') DEFAULT 'active' AFTER is_solution");
        echo "Added status column to forum_posts\n";
    } else {
        echo "status column already exists in forum_posts\n";
    }

    echo "Migration 012 completed successfully\n";
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage() . "\n";
    exit(1);
}
