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"); }