0

I've designed my MySQL database for a multi tenant application using the "Shared database, shared schema. A tenant identifier (tenant key) associates every row with the right tenant." structure as shown in this post.

I'm using Codeigniter as my PHP framework and Ion_Auth for authentication. When selecting data for a tenant, how do I avoid having an additional "where tenant_id = user_id" clause in every select query I run on the database. Implementing groups on Ion_Auth seems to be a basic way of doing this, but that will create it's own mess.

Is there a way to do this globally?

Robin Bantjes
  • 299
  • 4
  • 19

1 Answers1

0

You will need a tenant_id per table to separate the rows. For the SELECT you can create a VIEW with embedded the "WHERE tenant_id = user_id" clause. The user_id is the database user, so you need to create a database account per tenant. This gives a clear description: https://opensource.io/2017/12/07/mysql-multi-tenant/

FDS
  • 16
  • 2