tenancy icon indicating copy to clipboard operation
tenancy copied to clipboard

[4.x] Create or delete a tenant with different database tenantConfig properties like host

Open abrardev99 opened this issue 3 years ago • 4 comments

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.

abrardev99 avatar Sep 13 '22 11:09 abrardev99

I saw a todo related to a name: https://github.com/archtechx/tenancy/blob/master/src/Database/TenantDatabaseManagers/TenantDatabaseManager.php#L9-L12 image

I think we can rename it to TenantDatabaseManagerContract.

abrardev99 avatar Sep 14 '22 09:09 abrardev99

Two things to do here:

  1. Describe the changes in detail in the PR description — what this adds, how the solution works
  2. Based on our convo on BC, you can revert the latest commit

stancl avatar Sep 14 '22 19:09 stancl

Codecov Report

Merging #946 (836716c) into master (fe0a322) will increase coverage by 0.19%. The diff coverage is 96.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.

codecov-commenter avatar Sep 15 '22 05:09 codecov-commenter

Two things to do here:

  1. Describe the changes in detail in the PR description — what this adds, how the solution works
  2. Based on our convo on BC, you can revert the latest commit

Done.

abrardev99 avatar Sep 15 '22 06:09 abrardev99

@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.

stancl avatar Oct 04 '22 21:10 stancl

Is the label because this is still WIP?

stancl avatar Oct 09 '22 23:10 stancl

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.

abrardev99 avatar Oct 10 '22 08:10 abrardev99

@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.

abrardev99 avatar Oct 13 '22 04:10 abrardev99

Thanks for your work on this ❤️

stancl avatar Oct 31 '22 11:10 stancl