Files
saqel/backend/public/migrate.php
T

42 lines
1.3 KiB
PHP

<?php
// Script to run database migrations with full error feedback
require_once dirname(__DIR__) . '/app/bootstrap.php';
use App\Core\Database;
header('Content-Type: application/json; charset=utf-8');
try {
$db = Database::getConnection();
// Disable Foreign Key checks explicitly on the active connection
$db->exec("SET FOREIGN_KEY_CHECKS = 0;");
$sqlFile = dirname(__DIR__) . '/database_schema.sql';
if (!file_exists($sqlFile)) {
throw new \RuntimeException("Schema file not found at: {$sqlFile}");
}
$sql = file_get_contents($sqlFile);
// Execute SQL schema definition
$db->exec($sql);
// Re-enable Foreign Key checks
$db->exec("SET FOREIGN_KEY_CHECKS = 1;");
echo json_encode([
'status' => 'success',
'message' => 'تم إنشاء وهيكلة الـ 14 جدولاً بنجاح تام في قاعدة البيانات saqelDB! 🚀'
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
} catch (\Throwable $e) {
http_response_code(500);
echo json_encode([
'status' => 'error',
'error_type' => get_class($e),
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine()
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}