Explor Elixir E6: Multitenant Apps with Ecto and Triplex

Tags: #<Tag:0x00007f1142d2e010>


I am finally back with another episode of Exploring Elixir. Sorry for the long wait! My August was split between vacation and starting a new adventure at work, so EE got punted for the month. Back to weekly episodes now though …

In episode 6, we look at using Ecto and Triplex to create multitenant applications. Even for those who have used these tools before, there may be a couple tips in there for you yet, such as how to get the prefix to use from inside a Triplex migration …

Hope you enjoy, as always!


@kelvinst get a look :slight_smile:


Triplex author here! Really glad to see you enjoyed it to the point of making a video using it!

Your video is really awesome! It has a really nice overview for who wonders what does it do.

I was working on an article/tutorial of how to use it (@BarelyFunctional asked for it), but got no time to finish it yet! I promise I’ll work on it soon…

About the use of prefixes on migrations, that’s a nice catch. I actually had this problem but forgot to document my solution. Just a little thing you probably missed: there is a function that gets the prefix of the running migration for you - Ecto.Migration.prefix/0. It does exactly what you do, but without that much work! :wink:

Thanks @aseigo for all your work!


Dang, I completely missed that somehow. Been there since 2.0 as well! Will update the repo later to simplify with this … thanks, both for this tip but also the library!


It happens with everyone, more than it should, but that’s the way it is. :lol:

You’re welcome!


BTW … it is quite difficult to find triplex on hex.pm. It does not mention the magic term “multitenant” or “multitenancy” anywhere in the description, which is probably what many people search for (one such person already popped up in the comments on Reddit, in fact).

hex.pm mangles the markdown in the README.md description which doesn’t help any either. Even then, as someone who did not come to Elixir from Ruby, the reference and link to Apartment didn’t really help me find it, either.

You may wish to consider tweaking the descriptions on github and especially hex.pm to make it more discoverable?


Sure! Any suggestion?


I’ve opened this PR with a new description, what do you think?


Perhaps something like:

“A simple and effective way to build multitenant applications on top of Ecto. Keep data specific to each tenant (group of users) separate in the database using standard Ecto functions. Triplex includes mix tasks as well as a simple tenant management API to simplify defining and managing tenants.”



Looks great! It’s good to have native english speakers that are willing to help! Thanks!


@kelvinst Also adding some more topics on the github repo might help as well. Maybe “multitenant” , "SaaS, “apartment”.




Added! Thanks for the suggestion!