Module: Ec::Pg::SchemaMixin

Extended by:
ActiveSupport::Concern
Defined in:
lib/ec/pg/schema_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::SchemaMixin
  acts_as_namespaced
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_tenant class method for explicit scoping.

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