When creating a new tenant that should have a mysql db on a different host/server it fails
Describe the bug
I created a console command to create tenants. For our use case we want the tenant dbs hosted on different servers. So i added the tenancy_db_host. But this doesn't seem to do anything. If i hardcode the host in the template, it works.
Steps to reproduce
In config/database.php i have the 'template', here is a snippet. The env vars are there just as fallback.
'tenant_db' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
....
For the creation of the tenant i use this snippet:
$dbSettings['tenancy_db_connection'] = 'tenant_db';
$dbSettings['tenancy_db_host'] = $host;
if ($dbuser) {
$dbSettings['tenancy_db_username'] = $dbuser;
}
if ($dbpasswd) {
$dbSettings['tenancy_db_password'] = $dbpasswd;
}
$tenant = Tenant::create($dbSettings);
Expected behavior
I would expect that the host variable in the template would be overwritten with the tenancy_db_host key.
Your setup
- Laravel version: 7.28.4
- stancl/tenancy version: v3.2.1
- Storage driver: MySQL
Hello, I had the same issue with one of the projects I'm working on.
I have resolved the issue and have created a pull request. @stancl could you please check?
Closing since the PR is open