RefreshDatabase trait only dropping tables for main connection #32989
Replies: 9 comments 6 replies
-
Sounds like a feature request. Moving this to discussions. |
Beta Was this translation helpful? Give feedback.
-
I also ran into this bug. Would be great if I could optionally pass additional connections to refresh when calling refreshDatabase. |
Beta Was this translation helpful? Give feedback.
-
Has anyone come up with a fairly succinct or elegant workaround for this problem, or perhaps a best practice? I have a client who runs many copies of the same laravel app, with business data on a mysql server connection, but each with their users, menus, auth data stored locally on sqlite, such as that they can bulk (drop and create) export/import all of their business data from one site to another, without disturbing the user settings. Alternatively they occasionally migrate the users from one app to another when moving teams around, etc. Not being able to write tests for requested feature additions is a severe handicap. Nevermind. Using this for now
|
Beta Was this translation helpful? Give feedback.
-
Just been hit with this problem too. Main connection gets refreshed ok, but any other connections do not and so the migrations fail on the next test to be run. Will try getting the work around to work, but it would be nice for the |
Beta Was this translation helpful? Give feedback.
-
I had a chance to look at @StevePorter92's example. One thing that stood out to me is specifying the connection inside the migration file. public function up()
{
Schema::connection('mysql2')->create('tests', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
} I'm curious is this standard practice? That means there is a single migrations table on the default db for all the connections.
In this case, each database will have it's own migrations table, but it will also have empty tables that don't apply to each database. I don't have much experience using multiple connections so I'm interested to know how people are managing all this because it does seem odd to me if you can specify one connection in the migration and another in the parameter. Anyway, to address the original issue. if we change from I also like @maarten00's suggestion. Something like |
Beta Was this translation helpful? Give feedback.
-
This seems to work fine in Laravel 8.
|
Beta Was this translation helpful? Give feedback.
-
This is still broken in Laravel 9.42.2. If one is unaware of this problem in advance of running DB tests using the |
Beta Was this translation helpful? Give feedback.
-
still no fix for this ? |
Beta Was this translation helpful? Give feedback.
-
I'm using laravel with Postgres and I have multiple DB schemas. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
\Illuminate\Foundation\Testing\RefreshDatabase
runs themigrate:fresh
command which will only wipe tables on the main database connection.If running migrations on specific connections other than the main one, the tables for these connections will not be dropped so test runs after the first one will error with:
Given the
RefreshDatabase
trait can perform transactions on multiple connections with theconnectionsToTransact
property, should it alsodb:wipe
those connections too?Steps To Reproduce:
Fresh laravel project with steps to reproduce here https://github.com/StevePorter92/refresh-database-issue.
List of changed files: StevePorter92/refresh-database-issue@0d7e05c...master
Notable files:
Happy to raise a PR for this if we think the trait should wipe all connections, or connections that it transacts on
Beta Was this translation helpful? Give feedback.
All reactions