Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration run ordering #243

Closed
antonkomarev opened this issue Jun 3, 2019 · 6 comments
Closed

Migration run ordering #243

antonkomarev opened this issue Jun 3, 2019 · 6 comments

Comments

@antonkomarev
Copy link
Contributor

antonkomarev commented Jun 3, 2019

Orchestra v3.8.1

Orchestra runs migration in this order:

  1. Package migrations registered in package Service Provider: database/migrations
  2. Application published migrations: vendor/orchestra/testbench-core/laravel/database/migrations
  3. Package tests migrations: tests/database/migrations

I need to run package tests migrations first of all. How can I do it?

In TestCase.php I'm loading package test migrations:

protected function setUp(): void
{
    parent::setUp();

    $this->loadMigrationsFrom(__DIR__ . '/database/migrations');
}

In test file there is RefreshDatabase trait.

Here is an example where I found this issue: laravel-love/add-console-setup-commands. Tests are working good until this case is executed. It creates migration file in application. Next tests will fail because created migration will be runned before package test migrations which contains tables required for this case.

@antonkomarev antonkomarev changed the title Run application migrations first Migration run ordering Jun 4, 2019
@antonkomarev
Copy link
Contributor Author

antonkomarev commented Jun 4, 2019

Sorry, I was wrong with describing migration run order in initial post, so I've edited it.

@crynobone
Copy link
Member

What's the purpose of RefreshDatabase when you are testing with sqlite :memory: configuration?

@antonkomarev
Copy link
Contributor Author

This is the same config for all my repositories (some of them using mysql in tests). To be assure that everything will be migrated from scratch on each run.

@crynobone
Copy link
Member

Well, it's not useful and cause issue exactly as you experienced right now.

@crynobone
Copy link
Member

To be assure that everything will be migrated from scratch on each run.

:memory: already covers this. You don't need RefreshDatabase unless you are working with persistent database storage

@antonkomarev
Copy link
Contributor Author

@crynobone thanks. I've removed all RefreshDatabase traits usage and added manual migrate launching command:

$this->artisan('migrate', ['--database' => 'sqlite'])->run();

Now it seems to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants