[4.x] Create or delete a tenant with different database tenantConfig properties like host
Problem
When a tenant has its own database config (using the tenancy_db_... properties), the database manager still tries to create the DB on the central/template connection. The problem described in the related issue https://github.com/archtechx/tenancy/issues/515 is that tenancy_db_host is specified in the tenant config, but the package still uses the host from the template connection.
Solution
The solution is pretty straightforward. The main motivation is coming from this comment https://github.com/archtechx/tenancy/pull/656#issuecomment-841803111. I've created a new manager hostManager() method, which returns the manager with host connection. We use this manager to create, delete and check if exists database. A host connection is a new temporary connection created by replacing the template config with the tenant's config.
Replacing means we override the template connection with the values from the tenant config. This way, We are able to use the tenant configs, e.g., tenancy_db_* properties, to build the final connection.
I saw a todo related to a name: https://github.com/archtechx/tenancy/blob/master/src/Database/TenantDatabaseManagers/TenantDatabaseManager.php#L9-L12

I think we can rename it to TenantDatabaseManagerContract.
Two things to do here:
- Describe the changes in detail in the PR description — what this adds, how the solution works
- Based on our convo on BC, you can revert the latest commit
Codecov Report
Merging #946 (836716c) into master (fe0a322) will increase coverage by
0.19%. The diff coverage is96.29%.
@@ Coverage Diff @@
## master #946 +/- ##
============================================
+ Coverage 86.85% 87.05% +0.19%
- Complexity 484 495 +11
============================================
Files 124 124
Lines 1331 1367 +36
============================================
+ Hits 1156 1190 +34
- Misses 175 177 +2
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/Database/DatabaseConfig.php | 93.50% <96.29%> (+1.98%) |
:arrow_up: |
| src/Commands/TenantDump.php | 80.00% <0.00%> (ø) |
|
| src/Database/Models/Tenant.php | 100.00% <0.00%> (ø) |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
Two things to do here:
- Describe the changes in detail in the PR description — what this adds, how the solution works
- Based on our convo on BC, you can revert the latest commit
Done.
@abrardev99 I responded to a few reviews. In this PR, try to improve the tests based on what we discussed on BC recently. Then I'll review the PR again.
Is the label because this is still WIP?
Is the label because this is still WIP?
Yes, I'm making some changes to the tests. I'll remove the label once I've done.
@stancl I gave it a final review now. I replied to all of the reviews. I removed two tests because other tests are kind of doing the same. Please check open reviews.
Thanks for your work on this ❤️