tenancy / multi-tenant

Run multiple websites using the same Laravel installation while keeping tenant specific data separated for fully independent multi-domain setups, previously github.com/hyn/multi-tenant
https://tenancy.dev
MIT License
2.55k stars 392 forks source link

Default connection changes on migrate #369

Open PiranhaGeorge opened 6 years ago

PiranhaGeorge commented 6 years ago

Hi,

Just found a sneaky bug.

The tenancy:migrate command changes the default connection to tenant. This isn't a problem when using the command in the terminal, however, as it is also called from Connection::migrate(), creating a website changes the default database.

This is a huge issue for me as I'm changing the default connection via middleware so that I can use laravel passport for system and tenant apis.

I should get a chance to put in a pull request next week, unless someone else can do so sooner.

Cheers, George

luceos commented 6 years ago

We used to have a separate connection name for migrations, but in discussions with @Thijmen we decided to drop it assuming migrations would only be ran inside artisan anyway..

I think we should consider restoring that migration connection name, I would love to hear your opinions.

fletch3555 commented 6 years ago

@luceos, what if we just change it so tenant commands restore the previous state after running. So if the command needs to change to the tenant DB, then it should cache the old setting, and restore it once done. This should minimize any side-effects these commands may have, and simplify the config so it doesn't need extra connections