kelvinst

kelvinst

Triplex - a complete solution to multi-tenancy with PG schemas

Hey everyone!

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.

https://github.com/ateliware/triplex/

We’ve recently released version 1.1.2 with support for ecto 2.2.0-rc. :slight_smile:

I know there are some other options of libraries for the same purpose, like GitHub - Dania02525/apartmentex: SaaS support for Phoenix + Ecto · GitHub and GitHub - tweag/tenantex: Multi-tenant support for Ecto (Elixir) · GitHub. 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 Repo where to execute the tenant management tasks
    • Tenant names that must be reserved, like api or www if you’re using subdomains to load your tenant

There are also some differences in the way the libs handle the queries and commands with the prefix. While tenantex and 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 ecto:

Repo.all(User, prefix: org.subdomain)

Now the same query using a properly configured triplex:

Repo.all(User, prefix: Triplex.to_prefix(org))

The same with tenantex:

# 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)

Finally, with apartmentex:

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 ecto.

And one last thing: we got our docs a little bit further! That’s a bonus for anyone who wants to use it! :wink:

Feel free to try it and send feedbacks for us!

First Post!

l00ker

l00ker

I just did a mix phx.new triplex_test using Phoenix 1.3 and got this error.

$ mix deps.get
Running dependency resolution...

Failed to use "plug" (version 1.4.3) because
phoenix (version 1.3.0) requires ~> 1.3.3 or ~> 1.4
phoenix_ecto (version 3.2.3) requires ~> 1.0
phoenix_html (version 2.10.3) requires ~> 1.0
triplex (version 1.1.2) requires ~> 1.3.5
mix.lock specifies 1.4.3

Can the required plug version relaxed?

Most Liked

kelvinst

kelvinst

Heeey! Long time no see, but I’m here to announce 1.3.0 (not rc, the official one) is out! You can check the list of stuff on the release notice, but for those that have no time, the big thing on this release was the support to Ecto 3.

Hope that the lib is still useful for all of you and we are always open to contributions, but please do not be sad if we take some time to answer, there are not too many people on the core team for it and we are very busy lately.

Thanks!

kelvinst

kelvinst

1.2.0-rc is out!

Hey guys! Quick update: we got a new release!

Despite not having huge changes or new features, we have incremented the minor version for some reasons. You can check these reasons as well as the changelog here: Release 1.2.0-rc.0 · ateliware/triplex · GitHub

But for those who don’t have time do get there, the biggest things that are coming out with this release are:

  • Plug as an optional dependency, so if you don’t use any plug on your app, triplex will not add this dependency on your project.
  • The support for using triplex on OTP releases, which I really didn’t know we had a problem with, but now, thanks to @dustinfarris, we do not have it anymore! PS: if anyone does need this correction on a 1.1 patch release, please let me know.
  • Docs and README improved.
  • Refactors on plug configs and method return values.

Hope you’re liking to use it.

kelvinst

kelvinst

I’m here to announce the long awaited new version for Triplex!

Actually, it’s an RC for the new version. You know, we need to test it well before releasing it out in the wild.

Anyways, this version will come with the support for two new things: Ecto 3 and MySQL!

The details are here in the release notice: Release 1.3.0-rc.0 · ateliware/triplex · GitHub

Also, refer to the release notice for how to upgrade, since there are some breaking changes on Ecto 3 migrations that affected Triplex.create inside Repo.transactions.

With no further ado, we would be very grateful if you could test it out on your projects and let us know with github issues if any problem occurs!

Thank you all!

Last Post!

kelvinst

kelvinst

I particularly prefer to propagate the tenant myself, so I would go the way you did it too. But instead of sending the whole assigns, you could actually send only the loaded tenant to the context.

Where Next?

Popular in Announcing Top

kelvinst
Hey everyone! 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 m...
New
pkrawat1
Hey guyz We at @aviabird are working on a payment library in elixir/phoenix. We are targeting March 2018 to add 56 Gateways to it. Have...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 30486 241
New
devonestes
Introducing assertions, the library that helps you write really great test assertions! GitHub: GitHub - devonestes/assertions: Helpful a...
New
ityonemo
Currently just starting out on a new mini-project - getting zig NIFs to run in elixir. https://github.com/ityonemo/zigler The idea here...
New
Qqwy
TypeCheck: Fast and flexible runtime type-checking for your Elixir projects. Core ideas Type- and function specifications are const...
336 14774 100
New
dominicletz
Hi, I thought I had posted my library before but seems I hadn’t. The project is still in early stages but it’s growing and so I think it...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement