28 lines
930 B
PHP
28 lines
930 B
PHP
<?php
|
|
require_once 'config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Create migrations table if it doesn't exist
|
|
$pdo->exec("CREATE TABLE IF NOT EXISTS migrations (migration VARCHAR(255) PRIMARY KEY)");
|
|
|
|
// Get executed migrations
|
|
$executed_migrations = $pdo->query("SELECT migration FROM migrations")->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
$migration_files = glob(__DIR__ . '/migrations/*.sql');
|
|
foreach ($migration_files as $file) {
|
|
$migration_name = basename($file);
|
|
if (!in_array($migration_name, $executed_migrations)) {
|
|
$sql = file_get_contents($file);
|
|
$pdo->exec($sql);
|
|
|
|
$stmt = $pdo->prepare("INSERT INTO migrations (migration) VALUES (?)");
|
|
$stmt->execute([$migration_name]);
|
|
|
|
echo "Applied migration: " . $migration_name . "\n";
|
|
}
|
|
}
|
|
} catch (PDOException $e) {
|
|
die("Migration failed: " . $e->getMessage());
|
|
} |