I fully understand the pros and cons of using shared vs separate schemas (or databases in mysql). Looking at those we have chosen to use a shared schema.
Looking for ideas on how we can more easily accomplish multi-tenancy. I am happy to add a key to each table, but that means that we will need to add "where tenant_id = X" for every single table that uses multi-tenancy in every single query. Sounds painful.
A much better approach would be to set some parameter that affects all tables in a query or all queries in a connection. This would avoid having to update all existing queries and having to include checks for tenant ids in future queries.
I had some initial ideas (below), but they all seem pretty painful as well.
Create temporary views for each table that automatically filter by tenant id (possibly using temporary tables?)
Create views that filter by tenant id and dynamically set the table name in the query
Use partitions by tenant id and query individual partitions.
Anyone have any better ideas?