Narven
Hi,
For the last 2 days, I’ve be trying to implement Triplex to add multi-tenancy to my application, and I use transactions a lot, usually with Ecto.Multi.
From the documentation it looks like with triplex I need to use:
Triplex.create_schema(slug, Project.Repo, fn(tenant, repo) ->
Repo.transaction(fn ->
mig = Triplex.migrate(tenant, repo)
IO.inspect(mig, label: "MIGRATE")
// Add any ecto operation here...
tenant
end)
end)
My problem is that Triplex.migrate(tenant, repo) is always, always returning:
{:error,
"ERROR 42P01 (undefined_table) relation \"prj_c24.schema_migrations\" does not exist\n\n query: INSERT INTO \"prj_c24\".\"schema_migrations\" (\"version\",\"inserted_at\") VALUES ($1,$2)"}
For me this is an extreme confusing error. It tells nothing about what is happening, (at least for me).
My only migration is this:
defmodule Project.Repo.Migrations.CreateUsersTables do
use Ecto.Migration
def change do
# execute "CREATE EXTENSION IF NOT EXISTS citext", ""
create table(:users, primary_key: false) do
add(:id, :uuid, primary_key: true, null: false)
# add(:email, :citext, null: false)
add(:hashed_password, :string, null: false)
add(:first_name, :string, null: false)
add(:last_name, :string, null: false)
add(:is_enabled, :boolean, null: false, default: true)
add(:dob, :date)
add(:photo, :string, default: "/images/empty.png")
add(:confirmed_at, :naive_datetime)
timestamps()
end
# create unique_index(:users, [:email])
end
end
Any help on that error? thanks
PS: The prefix is being created in the database. But migrations are not running.
❯ elixir --version
Erlang/OTP 24 [erts-12.1.5] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit] [dtrace]
Elixir 1.13.0 (compiled with Erlang/OTP 24)
{:triplex, "~> 1.3.0-rc.1"}
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #ai
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
al2o3cr
The error is complaining because the
schema_migrationstable isn’t present in the tenant schema.That doesn’t make a ton of sense -
Triplex.migratecallsEcto.Migrator.runwhich ensures that table existsIs there anything useful in the Elixir or DB logs?
Narven
Yeah.. I was just looking at that. it looks like for some reason that “schema_migrations” is not being created on the tenants side.
Could it be because i have both “migrations” and “tenant_migrations” inside of “repo” folder ?
I was trying to see if there was a way to prevent the rollback. so that I could see the last state.
Narven
From the logs:
al2o3cr
Getting to the
== Running 2021etcetcetcbit suggests that the code believes it has created theschema_migrationstable.One thought: this pattern looks like the one mentioned in the Triplex docs, but I wonder if that actually works. Maybe the
schema_migrationstable is being inserted in a separate transaction somehow; that would produce the observed behavior:Repo.transactionin your posted codeTriplex.migratecalls intoEcto.Migrator, which starts a transaction in another process (the migration lock holder?)Ecto.Migratortries to read fromschema_migrationsand failsNarven
One thing I dont understad is that if I go and run
iex -S mix phx.serverand on iex i run:
It works flawless.
If I run
Triplex.create("foo")directly on the code… Does do nothing.Because for some weird reason according to the docs we have to run
create_schema. But on IEX just runningcreateworks perfectly.Narven
If I do something simple like:
it works. I think that the issue is only when they are running inside a migration.
al2o3cr
Yeah, that’s what makes me suspicious about the
Repo.transactionin the middle -Triplex.createis defined in a way that’s equivalent to:Re: your last message about running inside a migration - if this code is inside a migration’s
def up, then there’s already a transaction wrapped around the whole thing. You may need to disable that with@disable_ddl_transaction true.Narven
It looks like adding
@disable_ddl_transaction trueto the migration and doing like this:returns:
Still shows the error, which technally is an error, but in this case I dont think it should show has an error.
I think this is more like… I cannot find schema_migrations… so I’m going to create it. Or maybe not.
But for now it looks like is working… I will add tomorrow all the extra removed migrations and add the rest of the transactions to see how it goes.
Thanks @al2o3cr
Narven
After more testing… this lib does not work at all.
This working if there is only
onemigration, after that for some reason it throws the errorand no other migration get’s run:
i’ve currently have 2 migrations and this is what happens:
PS: added some extra debug lines to the actual library
§riebeekn
I think the inner transaction is the issue. As mentionned in the Triplex docs the way migrations run was changed in Ecto 3. Since that change I haven’t ever been able to get
Triplex.migrateto run within a transaction. Consideringcreate_schemawill do a schema drop on any{:error, some_err_message}result… not using a transaction seems an alright way of going about things.So I would try something along the lines of: