Module: Ec::Pg::RlsMixin

Extended by:
ActiveSupport::Concern
Defined in:
lib/ec/pg/rls_mixin.rb

Overview

Mixin for ActiveRecord models that participate in multi-tenancy.

Include via acts_as_rls in your model or add it to ApplicationRecord.

Usage

class ApplicationRecord < ActiveRecord::Base
  include Ec::Pg::RlsMixin
  acts_as_rls
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_rls class method for explicit scoping.

  • Optionally raises TenantNotSet when required: true and no tenant is set.

Defined Under Namespace

Classes: RlsError

Constant Summary collapse

RlsModes =
%i(local session)