Summer Sale! All accounts are 50% off this week.

Zivko's avatar
Level 10

Testing - Migrations from different directories

Hey guys, I have two directories with migrations. Default migrations are in "database/migrations". My additional migrations which are related only to one part of the app are in "database/migrations/onboarding-form". I figured out that the test doesn't run migrations from "database/migrations/onboarding-form" but only the default migrations. Is there anybody who knows how can I run tests which will run all migrations, from other locations and from the default one? Thanks!

0 likes
4 replies
Sinnbeck's avatar

You can use --path to specify one or more paths

php artisan migrate --path database/migrations/onboarding-form
//or
$this->artisan('migrate:refresh', ['--path' => 'database/migrations/onboarding-form']);
1 like
tykus's avatar
tykus
Best Answer
Level 104

Yes, you can explicitly run migrations in the sub directory if you modify the createApplication method, e.g.

// tests/CreatesApplication.php
public function createApplication()
{
    $app = require __DIR__.'/../bootstrap/app.php';

    $app->make(Kernel::class)->bootstrap();
    // add this
    $this->afterApplicationCreated(function () {
        $this->artisan(‘migrate’, [‘—path’ => ‘database/migrations/onboarding-form’]);
    });

    return $app;
}
1 like

Please or to participate in this conversation.