What is Apartment and when to use it
mainApartment provides database-level multitenancy for Rails and ActiveRecord. It isolates tenant data using either schema-per-tenant (PostgreSQL) or database-per-tenant (MySQL/SQLite). This ensures data separation is enforced by the database engine rather than application logic.
When to use Apartment
Use Apartment when you require hard data isolation, such as in regulated industries or B2B SaaS with contractual isolation requirements. It is ideal for:
- Fewer high-value tenants.
- Regulatory compliance requirements.
- Retrofitting existing single-tenant applications.
When to use Row-level tenancy instead
If you have hundreds of tenants, need to perform cross-tenant reporting, or are building a greenfield application, consider row-level tenancy (e.g., using acts_as_tenant) as it is simpler and scales more linearly.