php - Laravel: get records from multiple schemas

240

I am building a SaaS application that has a set of requirements. One of these requirements is that the application has to be multi-tenant with a seperate schema for every tenant. But there has to be a single instance (admin interface) that needs to access all those schemas for data validation.

Example:
We have x customers who will access their application through customerx.our-company.com. Every customer gets its own schema with multiple tables. These tables contain users, invoices, contracts, timesheets,... The customer has to be able to view/modify these records.

We as a company providing the service have to be able to get all the timesheets from all those customers to be able to verify them. Once verified these records will be updated.'verified' => true

My first idea was to store atenant_id in acustomers table in the admin database to be able to change the database connection in eloquent and merge the records before returning them. This is doable, but I have some questions about performance. What if we grow to 1000+ customers. getting all those records could take a long time.

Dumping all the records in a single schema without providing a separate schema per customer cannot be done because of GDPR. The data of the customer has to be separated.

What would be the best approach for this design wise? Are there some good articles about this subject?

What I began to think while writing this question: It is possible to leverage c++, I can create a custom PHP extension that takes multiple tenant database info to get the records via async tasksstd::async, merge those records and return them.std::async creates multiple threads in a pool and I can wait until it is finished. The only big deal will be relations that need to be returned. Updating those records is a simpler task as we know where it is stored (customer_id) so we can change the DB connection on the fly while updating.

EDIT: I created a simple c++ program that creates async MySQL connections. I've tested this with 10 schemas at once retrieving 1000 records from each. This looks promising, will keep this updated.

People are also looking for solutions to the problem: php - How to load HTML into a <div> using jQuery in WordPress?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.