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

JEG2
I’m closing out, for now, my series on questions at the heart of development with an analysis of when we need more abstraction. For exam...
New
New
axelson
I talk about how I really like to use runtime configuration and discuss some common pitfalls of configuration in Elixir.
New
brainlid
This post asks if we can remove Alpine from the PETAL stack. Can we do everything we need with just LiveView? Also, let’s explore an area...
New
paulanthonywilson
So you’re enjoying using WebSockets with Elixir’s Phoenix Framework, and you want to send some binary messages. Maybe it’s an audio clip,...
New
AstonJ
Update: How to use the blogs section You can post in one of the Official Blog Posts threads (like this one), or, via Devtalk and a new t...
New
shanesveller
Introduction and first content post in my new series about running Elixir Phoenix apps on Kubernetes are live! I’m describing an opiniona...
New
AstonJ
Elixir Blog Posts How to use this section You can post links to your blog posts either in one of the Official Blog Posts threads, or, vi...
New
SmartLogic
Season four of the Elixir Wizards podcast launches today! This season we’re focused on system and application architecture. We’ll be doin...
New
paulanthonywilson
I had a bit of a mini-adventure following Sobelow’s advice on adding a CSP to a Phoenix App. If you want to follow along, or want to add ...
New

Other popular topics Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement