Well, we made this lib a while ago and now we decided to finally go out and public with it! It’s a tool for creating and managing multi-tenancy applications using postgres schemas.
We’ve recently released version
1.1.2 with support for ecto
I know there are some other options of libraries for the same purpose, like https://github.com/Dania02525/apartmentex and https://github.com/promptworks/tenantex. At the time we wrote this lib, the other libraries were a little bit out of date with their pull requests, didn’t have everything we wanted and, the worst for us, were a little bit intrusive (I’ll talk about it later).
So we decided to write a simple one, and now here we are, another option for you. Here is a list of features we missed on the other libraries:
- Mix tasks for migrating and rollbacking all schemas
- Plugs to load and ensure if the tenant is loaded from a param, session value or subdomain
- A way to infer the name of the tenant from a given struct which represents the tenant on your application
- Smarter configuration like:
- Set the default
Repowhere to execute the tenant management tasks
- Tenant names that must be reserved, like
wwwif you’re using subdomains to load your tenant
- Set the default
There are also some differences in the way the libs handle the queries and commands with the prefix. While
apartmentex are a little bit intrusive to your
Repo or the use of it, on
triplex we tried to stay the least intrusive we could.
For example, here is how to make a query applying a prefix from an tenant struct called
org on raw
Repo.all(User, prefix: org.subdomain)
Now the same query using a properly configured
Repo.all(User, prefix: Triplex.to_prefix(org))
The same with
# first you need to change your repo to use their repo not ecto's defmodule Repo do use Tenantex.Repo, otp_app: :your_app end Repo.all(User, prefix: org)
Apartmentex.all(Repo, User, org)
The reason behind this decision is simple: being less intrusive makes
triplex a lot easier to upgrade for future versions of
And one last thing: we got our docs a little bit further! That’s a bonus for anyone who wants to use it!
Feel free to try it and send feedbacks for us!