From 7e3bd8a534f309061a9c34b4ed3eb3576e2e065d Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Wed, 10 Jan 2024 19:32:33 -0600 Subject: [PATCH] Update CHANGELOG.md --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index da7cd29..9ae8d19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,21 @@ Unreleased ---------- +* Add `config.tenant_change_hook` callback when a tenant changes. [#333](https://github.com/ErwinM/acts_as_tenant/pull/333) + +This can be used to implement Postgres's row-level security for example + +```ruby +ActsAsTenant.configure do |config| + config.tenant_change_hook = lambda do |tenant| + if tenant.present? + ActiveRecord::Base.connection.execute(ActiveRecord::Base.sanitize_sql_array(["SET rls.account_id = ?;", tenant.id])) + Rails.logger.info "Changed tenant to " + [tenant.id, tenant.name].to_json + end + end +end +``` + 1.0.1 -----