ragamuf

ragamuf

Elixir Blog Post: Speed up Multitenant Migrations with Database Schema Snapshots

Who doesn’t want to go faster? Migrations in Elixir with Ecto are already quick. Still, we can go faster, especially when we need to onboard customers repeatedly in multi-tenant architectures.

Most Liked

cjbottaro

cjbottaro

Neat!

We do something very similar. We have a “template” Pg schema that we dump/load on demand when a new tenant is created. The name of the schema is "__schema_$template", which is extremely likely to be to be unique when we run String.replace (or sed, can’t remember) on the dump output.

I’m a little confused how your #{prefix} works. Is that literally the name of your Pg schema?

One thing that I love about Ecto is how easy it is to do multitenancy. Between get_dynamic_repo, and default_options, it’s pretty easy to handle multietenancy (besides migrations, but that’s a story for another day).

Contrast that to Rails where they implemented first class support for multitenancy, but it’s very prescriptive about how it works… and further it makes a connection pool per tenant:man_facepalming:

ragamuf

ragamuf

Glad to hear that you have a similar process working well for you. Reusing the connection pool is a big deal. The prefix is just a placeholder like yours. I could have named it anything. The snapshot function returns a function that takes a specific prefix as an argument. This creates the unique schema for each tenant.

Did you run into any SSL invoking psql from System.cmd?

cjbottaro

cjbottaro

Nope, no SSL issues at all. We just use the Amazon managed certs for RDS and everything just works.

Where Next?

Popular in Blog Posts Top

biportal
Hi, I recently thought about a name for this Stack: Rust + Elixir + Phoenix. I came up with Runix (RuNix) and blogged about it on Medium....
New
John-BoothIQ
TL;DR: Good: AI is great at Elixir. It gets better as your codebase grows. Bad: It defaults to defensive, imperative code. You need...
New
marcelo
Long story short, over the past years we’ve been scaling our operation quite a lot at Unbabel. Most of our codebase is Python and some of...
New
ErlangSolutions
Hey all, it’s Erlang Solutions. We released loads of Elixir content from our senior developers last week in celebration of ElixirConf US...
New
aymanosman
This is a very short article about using AWS Systems Manager Parameter Store to load secret configuration in a simple way.
New
victorbjorklund
I’m showing you how you can customise the phx.new generator to give you a new Phoenix project the way YOU want it. In this post I show yo...
New
JKWA
I didn’t have room for this in my book, Advanced Functional Programming with Elixir , but I still thought it was worth sharing on my blog.
New
zacksiri
In December of 2023 we came to the realization that we needed to build our own image server. After hitting a few snags we decided that it...
New
rms.mrcs
Hi, everyone! In this article I describe how I created a simple metrics engine that can list to Hackney metric updates and send this data...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126226 1237
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53578 245
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

We're in Beta

About us Mission Statement