Files
musadaq-saas/scripts/legacy_migrations/migrate_008.php
T

44 lines
1.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* CLI-ONLY migration script.
* Moved out of the public webroot on 2026-07-30 - it used to be reachable
* unauthenticated over HTTP. Run with: php scripts/legacy_migrations/<file>
*/
if (PHP_SAPI !== 'cli') {
http_response_code(404);
exit('Not Found');
}
require_once __DIR__ . '/../../app/bootstrap/init.php';
use App\Core\Database;
try {
$db = Database::getInstance();
$sql = file_get_contents(__DIR__ . '/../../database/migrations/008_invoice_lines_enhance.sql');
// Split by semicolon and execute
$queries = array_filter(array_map('trim', explode(';', $sql)));
echo "<h1>Running Migration 008...</h1>";
echo "<ul>";
foreach ($queries as $query) {
if (empty($query)) continue;
try {
$db->exec($query);
echo "<li>✅ Executed: <pre>" . htmlspecialchars(substr($query, 0, 70)) . "...</pre></li>";
} catch (\Exception $innerE) {
if (str_contains($innerE->getMessage(), 'Duplicate column name')) {
echo "<li>ℹ️ تخطي (العمود موجود مسبقاً): <pre>" . htmlspecialchars(substr($query, 0, 70)) . "...</pre></li>";
} else {
throw $innerE;
}
}
}
echo "</ul>";
echo "<h2>Migration completed successfully!</h2>";
echo "<p>Please delete this file (public/migrate_008.php) for security.</p>";
} catch (\Exception $e) {
echo "<h2 style='color:red;'>Migration failed:</h2>";
echo "<pre>" . htmlspecialchars($e->getMessage()) . "</pre>";
}