Merge pull request #311 from basecamp/flavorjones-extracted-resolver

Update to AR::Tenanted with the extracted tenant resolver
This commit is contained in:
Mike Dalessio
2025-03-19 13:38:21 -04:00
committed by GitHub
3 changed files with 10 additions and 6 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ git_source(:bc) { |repo| "https://github.com/basecamp/#{repo}" }
ruby file: ".ruby-version"
gem "rails", github: "rails/rails", branch: "main"
gem "active_record-tenanted", bc: "active_record-tenanted", branch: "fizzy-temporary"
gem "active_record-tenanted", bc: "active_record-tenanted", branch: "fizzy-temporary-2"
# Assets & front end
gem "importmap-rails"
+2 -2
View File
@@ -1,7 +1,7 @@
GIT
remote: https://github.com/basecamp/active_record-tenanted
revision: 8728b0ea622dfbc15dc27f9ec9086a12ef873430
branch: fizzy-temporary
revision: dcb9ee57eebfa85ed5a521c40266a0caaecc4a58
branch: fizzy-temporary-2
specs:
active_record-tenanted (0.1.0)
activerecord (>= 8.1.alpha)
+7 -3
View File
@@ -1,6 +1,10 @@
Rails.application.configure do |config|
# uuugh this resolver proc is so gross.
config.middleware.use ActiveRecord::Tenanted::TenantSelector, "ApplicationRecord", ->(request) { request.subdomain.split(".").first }
Rails.application.config.after_initialize do
Rails.application.config.active_record_tenanted.tenant_resolver = ->(request) do
# in production, we're using a two-level subdomain like "tenant.fizzy.37signals.com", but in
# development and beta it's only a single-level subdomain.
tld_length = request.domain == "37signals.com" ? 2 : 1
request.subdomain(tld_length)
end
end
ActiveSupport.on_load(:action_controller_base) do