<?php
include('../includes/config.php');
if (!$con) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql_content = file_get_contents('create_permissions.sql');

// Split SQL by semicolon ensuring we don't break on escaped semicolons if any (simple split is usually fine for this)
$queries = explode(';', $sql_content);

echo "Executing Permission Schema Updates...\n";

foreach ($queries as $query) {
    $query = trim($query);
    if (!empty($query)) {
        if (mysqli_query($con, $query)) {
            echo "Query executed successfully.\n";
        } else {
            // Ignore "Duplicate entry" errors for INSERTs
            if (mysqli_errno($con) == 1062) {
                echo "Skipped duplicate entry.\n";
            } else {
                echo "Error: " . mysqli_error($con) . "\nQuery: " . substr($query, 0, 50) . "...\n";
            }
        }
    }
}
echo "Done.\n";
?>
