multi-tenancy: enforce tenant filters across all query types
- I have searched the issues of this repository and believe that this is not a duplicate.
Summary
I am looking for a recommended way to implement multi-tenancy in Ent with MySQL, where all tenant-aware tables are automatically scoped by tenant_id.
Interceptors seem useful for enforcing tenant filters and soft-delete filters globally, but some queries, such as HasX / edge-existence queries, do not appear to work as expected with interceptors. Because of this, I currently need to manually add tenant/soft-deletions specific Where conditions in multiple places.
Is there a recommended approach to enforce tenant-aware reads consistently across all query types, including edge and HasX queries, without manually passing tenant_id conditions everywhere?
Motivation
In a shared MySQL database, missing a tenant filter can cause cross-tenant data exposure. Centralized tenant enforcement would make Ent-based multi-tenant applications safer and easier to maintain, especially when combined with soft deletes and other global filters.
Source: ent/ent