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

Multiple database setup issue #99

Closed
sausin opened this issue Jul 29, 2020 · 3 comments
Closed

Multiple database setup issue #99

sausin opened this issue Jul 29, 2020 · 3 comments

Comments

@sausin
Copy link
Contributor

sausin commented Jul 29, 2020

A new issue has come up after introduction of #92

I have a mysql database setup which has tenant and landlord databases and another set on sqlite (used for testing). Before introduction of the above PR I was able to migrate and seed these databases by just specifying the connections on the artisan commands.

I.e. the below commands all worked without issues:

php artisan migrate:fresh --path=database/migrations/landlord
php artisan tenants:artisan "migrate:fresh --seed --database=tenant"

for mysql. And:

php artisan migrate:fresh --path=database/migrations/landlord --database=testing_landlord
php artisan tenants:artisan "migrate:fresh --seed --database=testing_tenant"

for sqlite setup. However, since the connections must be specified in the config file now this setup no longer works without having to change the config file before working on each database.

If this is the intended behavior going forward, it would be great to know the correct way to work through this issue.

@masterix21
Copy link
Collaborator

masterix21 commented Aug 1, 2020

Don't you ever change your landlord connection anyway if you switch from landlord to testing_landlord?

I tried to simulate your code: the SQLite migration for landlord works, but without switching the landlord connection to testing_landlord, my application can't switch to the right tenant database.

Why can't you use an environment variable to set up the landlord/tenant database connection? Should switch easier using .env and phpunit.xml.

Please help me to understand.

@sausin
Copy link
Contributor Author

sausin commented Aug 3, 2020

@masterix21 Thanks for your reply.

So the tests are run on the sqlite connection while I "use" the application in local environment on the mysql connection. The setup described in the original post worked before the referenced PR.

If there is a convenient way to continue using like before, that would be great. My workaround at the moment is to change the environment variables to get things to work.

@masterix21
Copy link
Collaborator

Yes, I think you have already found the best solution: switching to environment variables, you'll retake full control of your code (using .env and phpunit.xml).

// config/multitenancy.php
'landlord_database_connection_name' => env('DB_CONNECTION_LANDLORD', 'landlord');
'tenant_database_connection_name' => env('DB_CONNECTION_TENANT', 'tenant'),

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

No branches or pull requests

3 participants