A Ruby on Rails gem for row-level multi-tenancy using a shared database strategy.
ActsAsTenant is a Ruby on Rails gem that implements row-level multi-tenancy, allowing a single Rails application to serve multiple tenants (like different accounts or organizations) from a shared database. It automatically scopes all database queries to the current tenant, ensuring data isolation without requiring separate databases or schemas for each tenant.
Rails developers building SaaS applications, internal tools, or any multi-tenant system where data from different customers or groups must be securely separated within a single database.
Developers choose ActsAsTenant for its seamless Rails integration, robust security against tenant leakage, and flexibility in tenant identification. It simplifies multi-tenancy without the complexity of schema-based approaches, making it ideal for shared database setups.
Easy multi-tenancy for Rails in a shared database setup.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses Rails' default_scope to automatically filter all model queries by the current tenant, ensuring data isolation without manual code, as highlighted in the scoping examples.
Supports multiple methods to set the current tenant, including subdomain lookup, manual controller setup, and blocks, detailed in the 'Setting the current tenant' section.
Seamlessly works with ActiveJob, Sidekiq, and DelayedJob to preserve tenant context in jobs, preventing data leakage in asynchronous processes.
Includes safeguards against tenant scoping circumvention and configurable require_tenant checks, as emphasized in the philosophy and configuration options.
Relies on ActiveRecord's default_scope, which can introduce performance issues and conflicts with other default_scopes in models, a known Rails limitation.
Requires middleware and careful configuration for integration tests, as shown in the testing section, adding development overhead and boilerplate code.
Tightly coupled with ActiveRecord, making it unsuitable for applications using alternative ORMs or those planning to migrate away from Rails.