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.56k stars 393 forks source link

Initializing newly created tenant database #428

Closed redroses closed 6 years ago

redroses commented 6 years ago

After successfully creating a new customer, hostname and website, I am struggling to get initialize the newly created tenant database.

The tenant database gets created with a corresponding db user with all db permissions set correctly. All migrations are run and the tables get created. But the table initialization code only works on windows and not ubuntu.

The tenant database gets initialized on windows and not ubuntu. By initialized - all lookup tables are seeded, the default user is inserted and user preference record is inserted.

WORKS on windows 7 or 10. mysql 5.7.9 (going to try and update windows to mysql 5.7.21) apache 2.4.33 php 7.1.15

FAILS on ubuntu 17.10 mysql 5.7.21 apache 2.4.33 PHP 7.1.16

Questions: Does the tenant db connection get automatically set after creating a new tenant database? Appears to on windows setup. The migrations work on both If not, how can I force the tenant connection to the new tenant database?

Not sure how to handle - or if I'm supposed to. public function __construct( Config $config, PasswordGenerator $passwordGenerator, DatabaseManager $db, Kernel $artisan ) { $this->config = $config; $this->passwordGenerator = $passwordGenerator; $this->db = $db; $this->artisan = $artisan;

    $this->enforceDefaultConnection();
}

When a browser hits a subdomain.domain.com it correctly sets the tenant db.

luceos commented 6 years ago

I can't really make sense of your issue as to what the exact problem is aside from Windows identifying the tenant after it being created whereas Linux does not?

Does the tenant db connection get automatically set after creating a new tenant database? Appears to on windows setup.

No it won't, unless you hit the hostname of a tenant after creating.. To know for sure I'd like to know how you create tenants, is it done from a form or in terminal?

redroses commented 6 years ago

I updated windows mysql database to 5.7.21 Everything still works on windows. On ubuntu 17.10, the database seeds and any tenant table inserts right after the newly created tenant db and user do NOT persist. The same code persists to the windows tenant db.

WORKS on windows 7 or 10. mysql 5.7.21 apache 2.4.33 php 7.1.15

FAILS on ubuntu 17.10 mysql 5.7.21 apache 2.4.33 PHP 7.1.16

luceos commented 6 years ago

On ubuntu 17.10, the database seeds and any tenant table inserts right after the newly created tenant db and user do NOT persist.

They do not persist? Are they causing an error? Aside from not showing up are there other indications? Also did you set up both environments differently, eg the queue driver?

luceos commented 6 years ago

Let's stick to #429 👍