API Reference ExTenant v0.2.1

Modules

Call the use ExTenant macro to inject all the required behaviour into your Application Repo module to enable all multi-tenancy functions.

Run the tenanted migrations

The function cast_tenanted(changset, attrs, allowed)

  • injects the tenant_id key/atom into the allowed fields
  • retrieves the tenant_id value from the process dictionary
  • injects the %{"tenant_id" => tenant_id} into the attrs map
  • and then calls the standard Ecto.Changeset.cast function

An exception will be raised in the following two situations

retrieve the tenanted migrations path using a default fallback

To use the Extenant.Schema in your schema modules

  • it injects the belongs_to relationship to the tenant
  • it also raises a compiler error if the tenanted() call was omitted
  • it works with the tenant_id field set in Config.exs

Here is an example

defmodule Post do
  use ExTenant.Schema
  use ExTenant.Changeset

  tenanted_schema "posts" do
    field(:name, :string)
    field(:body, :string)

    tenanted()
  end
end

utility functions for retrieving the subdomain from the conn.host

Mix Tasks