Module: Ec::Pg::ShardMixin
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/ec/pg/shard_mixin.rb
Overview
Mixin for ActiveRecord models that participate in multi-tenancy.
Include via acts_as_sharded in your model or add it to ApplicationRecord.
Usage
class ApplicationRecord < ActiveRecord::Base
include Ec::Pg::ShardMixin
acts_as_sharded
end
What it does
-
Adds an
around_action-compatible callback that applies RLS before every query on the model when a tenant is active in the thread context. -
Provides a
with_tenantclass method for explicit scoping. -
Optionally raises TenantNotSet when required: true and no tenant is set.