From ad194ba1e0f0326e464b56b3feccaf957f64a0f9 Mon Sep 17 00:00:00 2001 From: Riccardo Binetti Date: Wed, 13 Dec 2023 22:55:36 +0100 Subject: [PATCH] Disable process dictionary based multitenancy We're going to move into passing the tenant explicitly, and the two solutions can't coexist. Signed-off-by: Riccardo Binetti --- backend/lib/edgehog/repo.ex | 29 --------------------------- backend/test/edgehog/tenants_test.exs | 1 - backend/test/support/data_case.ex | 11 ---------- 3 files changed, 41 deletions(-) diff --git a/backend/lib/edgehog/repo.ex b/backend/lib/edgehog/repo.ex index bf0cc6fcb..1065bdec5 100644 --- a/backend/lib/edgehog/repo.ex +++ b/backend/lib/edgehog/repo.ex @@ -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) @@ -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 -> diff --git a/backend/test/edgehog/tenants_test.exs b/backend/test/edgehog/tenants_test.exs index 3490b0202..09a6dd557 100644 --- a/backend/test/edgehog/tenants_test.exs +++ b/backend/test/edgehog/tenants_test.exs @@ -20,7 +20,6 @@ defmodule Edgehog.TenantsTest do use Edgehog.DataCase, async: true - @moduletag :no_tenant_fixtures alias Edgehog.Tenants alias Edgehog.Tenants.Tenant diff --git a/backend/test/support/data_case.ex b/backend/test/support/data_case.ex index 700ea9bb1..f42f3ce49 100644 --- a/backend/test/support/data_case.ex +++ b/backend/test/support/data_case.ex @@ -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 """