<?php
require __DIR__ . '/../includes/db.php';
try {
    // Find the first available executive to attach old records to
    $exec = $pdo->query("SELECT id FROM executives LIMIT 1")->fetch(PDO::FETCH_ASSOC);
    if ($exec) {
        $execId = $exec['id'];
        $pdo->exec("UPDATE trainings SET created_by_executive_id = {$execId} WHERE created_by_executive_id IS NULL");
        echo "Fixed past records by assigning them to executive ID: {$execId}";
    } else {
        echo "No executives found!";
    }
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}
