<?php

require_once __DIR__ . '/../db.php';

$coreSql = file_get_contents(__DIR__ . '/settings_module.sql');
$extensionsSql = file_get_contents(__DIR__ . '/settings_extensions.sql');

if ($coreSql === false) {
    exit("Unable to read settings_module.sql\n");
}

if ($extensionsSql === false) {
    exit("Unable to read settings_extensions.sql\n");
}

$sql = $coreSql . "\n\n" . $extensionsSql;

if ($conn->multi_query($sql)) {
    do {
        if ($result = $conn->store_result()) {
            $result->free();
        }
    } while ($conn->more_results() && $conn->next_result());
    echo "Settings core and extension tables created successfully.\n";
    exit(0);
}

echo "Failed to create settings module tables: " . $conn->error . "\n";
exit(1);
