33885-vm/db/migrate.php
Flatlogic Bot dfa8617644 1.1
2025-09-05 13:06:38 +00:00

34 lines
885 B
PHP

<?php
require_once 'config.php';
try {
$pdo = db();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$migrationsDir = __DIR__ . '/migrations';
$files = glob($migrationsDir . '/*.sql');
sort($files);
if (empty($files)) {
echo "No migration files found.\n";
} else {
foreach ($files as $file) {
$sql = file_get_contents($file);
if ($sql === false) {
throw new Exception("Could not read migration file: $file");
}
$pdo->exec($sql);
echo "Successfully executed migration: " . basename($file) . "\n";
}
}
echo "All migrations completed successfully.\n";
} catch (PDOException $e) {
die("Database migration failed: " . $e->getMessage() . "\n");
} catch (Exception $e) {
die("An error occurred: " . $e->getMessage() . "\n");
}