Uni Ecto Plugin Page
def list_users_raw do prefix = UniEcto.Plugin.get_tenant_prefix() Repo.query("SELECT * FROM #prefix.users") end What if your Settings table is global and Orders is per-tenant?
defmodule MyApp.Repo do use Ecto.Repo, otp_app: :my_app use UniEcto.Plugin, prefix_key: :tenant_prefix def all_tenants do # Could be a DB query or a static list ["public", "tenant_customer_a", "tenant_customer_b"] end end Step 3: Generate the Tenant Migrations The plugin usually provides a generator: uni ecto plugin
The uni_ecto_plugin provides a migration helper: def list_users_raw do prefix = UniEcto
If you are an Elixir developer using Phoenix Framework and Ecto, you have likely heard the siren call of the . Add the Plug to your router: defp deps
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:
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 :