<?php
// util/run_recaptcha_migration.php
require_once '../config.php';

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

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

// 1. Ensure settings table exists (re-run existing migration just in case)
$create_table_sql = "CREATE TABLE IF NOT EXISTS settings (
    id INT AUTO_INCREMENT PRIMARY KEY,
    setting_key VARCHAR(50) NOT NULL UNIQUE,
    setting_value TEXT,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";

if ($conn->query($create_table_sql) === TRUE) {
    echo "Settings table check passed.<br>";
} else {
    echo "Error checking settings table: " . $conn->error . "<br>";
}

// 2. Insert reCAPTCHA keys
$insert_sql = "INSERT IGNORE INTO settings (setting_key, setting_value) VALUES 
('recaptcha_site_key', ''),
('recaptcha_secret_key', '')";

if ($conn->query($insert_sql) === TRUE) {
    echo "reCAPTCHA settings inserted (if not existing).<br>";
} else {
    echo "Error inserting settings: " . $conn->error . "<br>";
}

$conn->close();
echo "Migration completed.";
?>