Ruby's ActsAsTenant gem equivalent for multi tenancy in Crystal

Hi, I am pretty new to Crystal with my background in Ruby (RoR), so this may be a dumb question.

I am looking for a shard or way to implement a shard for providing Multi Tenancy in a web app. In Ruby ActsAsTenant is pretty well known gem that I have used in 3-4 projects (which is based on ActiveSupport::CurrentAttributes ) to share a tenant set in top controller filter and access it in other layers of the application and automagically insert additional column in SQL where clause ( and tenant_id='your-tenant-id').

My questions are

  1. Is there a shard that will fulfill this need?
  2. If not, what concepts or patterns do I need to know to implement such a shard?

One of the major differences between the ecosystems of Crystal and Ruby is that there isn’t really a de-facto web framework.

How you accomplish this will depend a lot on which web framework you use. I don’t believe any of them have this baked in, but all of them have some notion of “who is the current user”. You’ll have to extend or duplicate this functionality to implement multi tennancy.

Best of luck!


If I may add… As DHH himself says multi-tenancy is what makes scaling hard, you might want to consider if something like ActsAsTenant is what you really need.

If each tenant is in fact isolated, just giving each their own database might be simpler.

1 Like