37 lines
950 B
PHP
37 lines
950 B
PHP
<?php
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
echo "Connected to database successfully.\n";
|
|
|
|
$migrationsDir = __DIR__ . '/migrations';
|
|
$files = glob($migrationsDir . '/*.sql');
|
|
|
|
if (empty($files)) {
|
|
echo "No migration files found.\n";
|
|
exit;
|
|
}
|
|
|
|
sort($files);
|
|
|
|
foreach ($files as $file) {
|
|
echo "Applying migration: " . basename($file) . "...\n";
|
|
$sql = file_get_contents($file);
|
|
// PDO does not support multiple queries in one call, so we need to split them.
|
|
$statements = array_filter(array_map('trim', explode(';', $sql)));
|
|
foreach ($statements as $statement) {
|
|
if (!empty($statement)) {
|
|
$pdo->exec($statement);
|
|
}
|
|
}
|
|
echo "Applied successfully.\n";
|
|
}
|
|
|
|
echo "All migrations applied.\n";
|
|
|
|
} catch (PDOException $e) {
|
|
die("Database error: " . $e->getMessage() . "\n");
|
|
}
|
|
|