Skip to content

Instantly share code, notes, and snippets.

@Kovah
Last active May 20, 2021 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kovah/fc411c997f8d71586dc567582375ee11 to your computer and use it in GitHub Desktop.
Save Kovah/fc411c997f8d71586dc567582375ee11 to your computer and use it in GitHub Desktop.
Run Laravel migrations up to a specific migration and stop there
<?php
// Run all database migrations up to a specific migration and stop there. Useful for testing migrations which alter data or mess with your models.
function migrateUntil(string $migration): void
{
$migrator = app('migrator');
$dbPath = base_path('database/migrations');
$migrations = collect($migrator->getMigrationFiles($dbPath))
->takeUntil($dbPath . '/' . $migration);
Artisan::call('migrate', ['--realpath' => 'true', '--path' => $migrations->values()]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment