Skip to content

Commit

Permalink
Disable process dictionary based multitenancy
Browse files Browse the repository at this point in the history
We're going to move into passing the tenant explicitly, and the two solutions
can't coexist.

Signed-off-by: Riccardo Binetti <[email protected]>
  • Loading branch information
rbino committed Dec 13, 2023
1 parent cf01e54 commit ad194ba
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 41 deletions.
29 changes: 0 additions & 29 deletions backend/lib/edgehog/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ defmodule Edgehog.Repo do

require Ecto.Query

@tenant_key {__MODULE__, :tenant_id}

def put_tenant_id(tenant_id) do
Process.put(@tenant_key, tenant_id)
end

def get_tenant_id do
Process.get(@tenant_key)
end

def fetch(queryable, id, opts \\ []) do
{error, opts} = Keyword.pop_first(opts, :error, :not_found)

Expand All @@ -51,25 +41,6 @@ defmodule Edgehog.Repo do
end
end

@impl true
def prepare_query(_operation, query, opts) do
cond do
opts[:skip_tenant_id] || opts[:schema_migration] ->
{query, opts}

tenant_id = opts[:tenant_id] ->
{Ecto.Query.where(query, tenant_id: ^tenant_id), opts}

true ->
raise "expected tenant_id or skip_tenant_id to be set"
end
end

@impl true
def default_options(_operation) do
[tenant_id: get_tenant_id()]
end

def transact(fun, opts \\ []) do
transaction(
fn ->
Expand Down
1 change: 0 additions & 1 deletion backend/test/edgehog/tenants_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

defmodule Edgehog.TenantsTest do
use Edgehog.DataCase, async: true
@moduletag :no_tenant_fixtures

alias Edgehog.Tenants
alias Edgehog.Tenants.Tenant
Expand Down
11 changes: 0 additions & 11 deletions backend/test/support/data_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,6 @@ defmodule Edgehog.DataCase do
setup tags do
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Edgehog.Repo, shared: not tags[:async])
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)

if tags[:no_tenant_fixtures] do
:ok
else
# Create a tenant fixture and populate the tenant id, since we don't have the web part that
# does it for us here
tenant = Edgehog.TenantsFixtures.tenant_fixture()
_ = Edgehog.Repo.put_tenant_id(tenant.tenant_id)

{:ok, tenant: tenant}
end
end

@doc """
Expand Down

0 comments on commit ad194ba

Please sign in to comment.