Uni Ecto Plugin May 2026
While Ecto provides the foundation for database communication, the uni_ecto_plugin extends its capabilities to handle the complex routing, migrations, and query scoping required for robust multi-tenant architectures. In this article, we will dive deep into what this plugin is, why you need it, and how to master its implementation. First, let's clarify the terminology. In the Elixir ecosystem, the term uni often refers to Universal Multi-Tenancy . The uni_ecto_plugin (typically found in libraries like triplex or the more modern ash_archival variants, or specifically the Uni package family) is a set of macros and helper functions that transform your standard Ecto repo into a multi-tenant powerhouse.
defmodule MyApp.Repo.Migrations.AddNotesToOrders do use Ecto.Migration import UniEcto.MigrationHelpers def up do # Runs on all existing tenants + public for tenant <- UniEcto.Plugin.all_tenants() do execute("SET search_path TO #tenant") alter table(:orders) do add :notes, :text end end end end uni ecto plugin
defp deps do [ :ecto_sql, "~> 3.0", :uni_ecto_plugin, "~> 0.5.0", # Hypothetical version :postgrex, ">= 0.0.0" ] end Run mix deps.get . The plugin requires you to use its TenantRepo behaviour. Modify your lib/my_app/repo.ex : In the Elixir ecosystem, the term uni often
mix uni_ecto.gen.migration create_tenants_table This creates a migration that tracks tenants in a central tenants meta-table. Add the Plug to your router: The plugin requires you to use its TenantRepo behaviour
In the modern landscape of Software as a Service (SaaS), multi-tenancy is no longer a luxury—it’s a necessity. Whether you are building a white-label CRM, an enterprise ERP, or a simple API for startups, you need a way to isolate customer data securely.
if Mix.env() == :prod do UniEcto.Plugin.set_tenant_prefix("public") end If you are searching for "uni ecto plugin," you might actually be looking for a specific adapter. Here is the landscape: