Last active
May 20, 2021 10:08
-
-
Save Kovah/fc411c997f8d71586dc567582375ee11 to your computer and use it in GitHub Desktop.
Run Laravel migrations up to a specific migration and stop there
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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