Skip to content

Instantly share code, notes, and snippets.

@Reizinixc
Created July 9, 2014 15:41
Show Gist options
  • Save Reizinixc/5dc6c2935637289617ac to your computer and use it in GitHub Desktop.
Save Reizinixc/5dc6c2935637289617ac to your computer and use it in GitHub Desktop.
Set all migration files was migrated.
<?php
$host = '127.0.0.1';
$dbname = 'database';
$username = 'root';
$password = '';
$migrationPath = '../app/database/migrations/';
$migrationFiles = array_diff(scandir($migrationPath), ['.', '..', '.gitkeep']);
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
$stmt = $pdo->prepare("INSERT INTO migrations VALUES (:migration, :batch)");
$pdo->query("DELETE FROM migrations");
foreach ($migrationFiles as $file) {
echo $stmt->execute(['migration' => pathinfo($file, PATHINFO_FILENAME), 'batch' => 0]) ? '.' : 'F';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment