45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
require_once 'config.php';
|
|
|
|
echo "Attempting to run migrations...\n";
|
|
|
|
try {
|
|
$pdo = db();
|
|
// Set error mode to exception to catch potential issues
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
$migrationsDir = __DIR__ . '/migrations';
|
|
|
|
if (!is_dir($migrationsDir)) {
|
|
mkdir($migrationsDir, 0775, true);
|
|
echo "Created migrations directory.\n";
|
|
}
|
|
|
|
$files = glob($migrationsDir . '/*.sql');
|
|
|
|
if (empty($files)) {
|
|
echo "No migration files found.\n";
|
|
exit;
|
|
}
|
|
|
|
sort($files);
|
|
|
|
foreach ($files as $file) {
|
|
$sql = file_get_contents($file);
|
|
if ($sql) {
|
|
$pdo->exec($sql);
|
|
echo "Executed migration: " . basename($file) . "\n";
|
|
}
|
|
}
|
|
|
|
echo "All migrations executed successfully.\n";
|
|
|
|
} catch (PDOException $e) {
|
|
// Use error_log for server-side logging instead of exposing details to the browser
|
|
error_log("Migration failed: " . $e->getMessage());
|
|
// Provide a generic error to the user
|
|
http_response_code(500);
|
|
die("Database migration failed. Check server logs for details.");
|
|
}
|
|
|