Multi tenant - Shared Database, Different Schema

I am developing an application that uses a central user table
for user authentication. After connection i would like each user to have a different schema.
(multi tenant strategy - shared database, different schema)

This lead us to have one model to handle multiple tables with same structure but different name.
i.e BookmarksTable model for ‘Bookmarks_tenantA’ and ‘Bookmarks_tenantB’ tables

I am looking for a way to pass the tenant_id into the initialize model function.
In that way i could initialize - handle each time different table.

i have found the following links

But i could n’t extract any useful information.

1 Like

Hello, I’m using a structure just like yours.

Inside the Controller in the beforeFilter Event I put the schema.table name like that.

CadastrosController extends AppController
{
    public function beforeFilter(Event $event) 
    {
        $session = $this->request->session();
        $empresa = $session->read('Empresa');
        if (isset($empresa->schemaname)){
            $this->Cadastros->table($empresa->schemaname.'.cadastros');
        }
....

My difficulty is when I create a new registry and it is necessary to create a new schema.

What is your vision when we have many registrations and many schemas … will it become a problem in the future?
Anyone else have any ideas about this?

This post is interesting, but with multiple databases mysql.