Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data-separation in a Symfony Multi-tenant app using Doctrine

I am trying to implement a multi-tenant application, that is - data of all clients in a single database - each shared table has a tenant_id field to separate data

I wish to achieve data separation by adding where('tenant_id = ', $user->getTenantID()) {pseudoc-code} to all SELECT queries I could not find any solution up-front, but here are possible approaches I am considering. 1) crude approach: customizing all fetchAll and fetchOne functions in every class (I will go mad!) 2) using listeners: possibly coding for the preDqlSelect event and adding the 'where' to all queries 3) override buildQuery(): could not find an example of this for front-end 4) implement contentformfilter: again need a pointer

Would appreciate if someone could validate these & comment on efficieny, suitability. Also, if anyone has achieved multitenancy using another strategy, pl share. Thanks

like image 630
Prasad Avatar asked Sep 21 '25 11:09

Prasad


1 Answers

I'm working out a solution using Doctrine Record Listeners by coding the preDqlSelect event. I think this is the best & easiest way to do things in a generic way, rather than having to modify every Table class and writing Tenant aware queries. With listeners, multi-tenancy will be completely transparent to developers.

Thanks for participating.

like image 80
Prasad Avatar answered Sep 23 '25 21:09

Prasad