Tenant resolver question #178
Unanswered
AlexStavrianos
asked this question in
Q&A
Replies: 2 comments
|
@AlexStavianos Thanks for the question.
No, that's not right. Tenants will never be implicitly created, you will need to explicitly create a tenant by calling
If you'd like to store untenanted data, you can do that by following the Rails Guide for multiple databases, and having a second abstract connection class in your application, e.g. class UntenantedApplicationRecord < ActiveRecord::Base
self.abstract_class = true
connects_to database: { writing: :untenanted, reading: :untenanted }
end
class ValidSubdomains < UntenantedApplicationRecord
endand # config/database.yml
production:
primary:
tenanted: true
adapter: "sqlite3"
database: "storage/tenants/%{tenant}/main.sqlite3"
untenanted:
adapter: "sqlite3"
database: "storage/untenanted.sqlite3"Does all that make sense? |
0 replies
|
Yeap, thank you very much.
…On Thu, 18 Sept 2025, 00:17 Mike Dalessio, ***@***.***> wrote:
@AlexStavianos <https://github.com/AlexStavianos> Thanks for the question.
If I read the source right I understand by default the gem will attempt to
create a shard/db if the tenant is unknown
No, that's not right. Tenants will never be implicitly created, you will
need to explicitly create a tenant by calling .create_tenant.
Where would you keep the list of allowed domains/subdomains? perhaps a
master untenanted db/shard?
If you'd like to store untenanted data, you can do that by having a second
abstract connection class in your application, e.g.
class UntenantedApplicationRecord < ActiveRecord::Base
self.abstract_class = true
connects_to database: { writing: :untenanted, reading: :untenanted }end
class ValidSubdomains < UntenantedApplicationRecordend
and
# config/database.ymlproduction:
primary:
tenanted: true
adapter: "sqlite3"
database: "storage/tenants/%{tenant}/main.sqlite3"
untenanted:
adapter: "sqlite3"
database: "storage/untenanted.sqlite3"
Does all that make sense?
—
Reply to this email directly, view it on GitHub
<#178 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMVPB6P7KBGMSJF5UA3F3EL3THFYDAVCNFSM6AAAAACGVTPF32VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTINBTGU2TKOA>
.
You are receiving this because you were mentioned.Message ID:
<basecamp/activerecord-tenanted/repo-discussions/178/comments/14435558@
github.com>
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello, my question is regarding the resolve tenant by request domain/subdomain. Where would you keep the list of allowed domains/subdomains? perhaps a master untenanted db/shard? If I read the source right I understand by default the gem will attempt to create a shard/db if the tenant is unknown which can lead to unwanted/spam shards?
All reactions