<?php
/**
 * Migration: Add enabling_pillars and thematic_categories columns to submissions table
 * Safe to re-run — checks if columns exist first.
 */
require_once 'config.php';

$columns_to_add = [
    'enabling_pillars' => "ALTER TABLE submissions ADD COLUMN enabling_pillars TEXT DEFAULT NULL AFTER service_chains",
    'thematic_categories' => "ALTER TABLE submissions ADD COLUMN thematic_categories TEXT DEFAULT NULL AFTER enabling_pillars",
];

echo "<h3>SaniBook DB Migration — Multi-Section Categorization</h3><pre>\n";

foreach ($columns_to_add as $col => $sql) {
    // Check if column already exists
    $check = $conn->query("SHOW COLUMNS FROM submissions LIKE '$col'");
    if ($check && $check->num_rows > 0) {
        echo "✓ Column '$col' already exists — skipping.\n";
    } else {
        if ($conn->query($sql)) {
            echo "✓ Added column '$col' successfully.\n";
        } else {
            echo "✗ Failed to add column '$col': " . $conn->error . "\n";
        }
    }
}

echo "\nDone.</pre>";
