Deploy from Lumerel
This commit is contained in:
34
migrate.php
Normal file
34
migrate.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// Migration runner
|
||||
require_once __DIR__ . '/src/db.php';
|
||||
|
||||
// Create migrations tracking table
|
||||
$pdo->exec("
|
||||
CREATE TABLE IF NOT EXISTS migrations (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
migration VARCHAR(255) NOT NULL UNIQUE,
|
||||
ran_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
");
|
||||
|
||||
// Get already-run migrations
|
||||
$stmt = $pdo->query("SELECT migration FROM migrations");
|
||||
$ranMigrations = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
// Scan and run new migrations
|
||||
$migrationFiles = glob(__DIR__ . '/migrations/*.php');
|
||||
sort($migrationFiles);
|
||||
|
||||
foreach ($migrationFiles as $file) {
|
||||
$migrationName = basename($file);
|
||||
|
||||
if (!in_array($migrationName, $ranMigrations)) {
|
||||
echo "Running migration: $migrationName\n";
|
||||
require $file;
|
||||
|
||||
$pdo->prepare("INSERT INTO migrations (migration) VALUES (?)")->execute([$migrationName]);
|
||||
echo "Completed: $migrationName\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "All migrations completed.\n";
|
||||
Reference in New Issue
Block a user