Fix database schema drop order, enhance migrate.php, and support server env paths
This commit is contained in:
@@ -1,17 +1,41 @@
|
||||
<?php
|
||||
// Script to run database migrations
|
||||
// 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::getInstance()->getConnection();
|
||||
|
||||
$sql = file_get_contents(dirname(__DIR__) . '/database_schema.sql');
|
||||
// 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);
|
||||
|
||||
echo "Database migrations executed successfully!\n";
|
||||
} catch (\Exception $e) {
|
||||
echo "Error executing migrations: " . $e->getMessage() . "\n";
|
||||
// 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user