Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
20 lines (16 sloc) 581 Bytes
defmodule Tenancy.Repo do
use Ecto.Repo,
otp_app: :ecto_tenancy_enforcer,
adapter: Ecto.Adapters.Postgres
@enforced_schemas [Tenancy.Company, {Tenancy.Person, :tenant_id}, {Tenancy.Alternate, :team_id}]
def init(_type, config) do
config = Keyword.merge(config, Application.get_env(:ecto_tenancy_enforcer, Tenancy.Repo))
{:ok, config}
end
def prepare_query(_operation, query, opts) do
unless Keyword.get(opts, :tenancy_unchecked) do
EctoTenancyEnforcer.enforce!(query, enforced_schemas: @enforced_schemas)
end
{query, opts}
end
end
You can’t perform that action at this time.