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

[12.x] Better support for multi-dbs in the RefreshDatabase trait #53231

Merged
merged 2 commits into from
Oct 29, 2024

Conversation

tonysm
Copy link
Contributor

@tonysm tonysm commented Oct 18, 2024

When working with multiple databases and some of them are in-memory while others are regular disk-based databases, we usually have to override some of the traits methods to make it work. Also, the database restoration process doesn't handle multiple DBs that well.

With these changes, when an app needs to support multiple databases, the user will have to do a few steps:

  1. Set the $connectionsToTransact protected property on the TestCase listing all connections they use
  2. Override the migrateDatabases method and call all the migrate:fresh commands for all their connections

The trait should now completely handle restoring the databases between tests, regardless of which database connection uses in-memory databases.


I'm sending this to 12.x because the API of the RefreshDatabase trait has changed. If this change is not considered BC, let me know so that I can send it to 11.x instead.

I'm using this trait in the app I'm working on that needs several databases and it's working.

When working with multiple databases and some of them are in-memory
while others are regular disk-based databases, we usually have to
override some of the traits methods to make it work. Also, the database
restoration process doesn't handle multiple DBs that well.

With these changes, when an app needs to support multiple databases, the
user will have to do a few steps:

1. Set the `$connectionsToTransact` protected property on the TestCase
listing all connections they use
1. Override the `migrateDatabase` method and call all the migrate:fresh
commands for all their connections

Restoring the databases between tests should now be completely handled
by the trait, no matter which database connection uses in-memory
databases or not.
@tonysm tonysm force-pushed the tm/multi-db-in-memory-restoration branch from d79a83e to 44ed600 Compare October 18, 2024 16:58
@taylorotwell taylorotwell merged commit a48c542 into laravel:master Oct 29, 2024
31 checks passed
@taylorotwell
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants