From e5f9217b4205bb05a995a4eb5265989cb46f1ee3 Mon Sep 17 00:00:00 2001 From: Corey Powell Date: Wed, 12 Jun 2024 18:37:27 -0500 Subject: [PATCH 1/5] use Mix.Config has been deprecated for some time now --- config/config.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.exs b/config/config.exs index a735e09..ba98045 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,6 +1,6 @@ # This file is responsible for configuring your application # and its dependencies with the aid of the Mix.Config module. -use Mix.Config +import Config # This configuration is loaded before any dependency and is restricted # to this project. If another project depends on this project, this From 661a04baeeac92ffa9718a62887b071bf15e5abf Mon Sep 17 00:00:00 2001 From: Corey Powell Date: Wed, 12 Jun 2024 18:37:49 -0500 Subject: [PATCH 2/5] Bump deps to deal with compiler warnings --- mix.lock | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mix.lock b/mix.lock index 849a042..d698f1b 100644 --- a/mix.lock +++ b/mix.lock @@ -1,7 +1,13 @@ %{ - "decimal": {:hex, :decimal, "1.4.1", "ad9e501edf7322f122f7fc151cce7c2a0c9ada96f2b0155b8a09a795c2029770", [:mix], [], "hexpm"}, - "earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], [], "hexpm"}, - "ecto": {:hex, :ecto, "2.2.8", "a4463c0928b970f2cee722cd29aaac154e866a15882c5737e0038bbfcf03ec2c", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, - "ex_doc": {:hex, :ex_doc, "0.18.1", "37c69d2ef62f24928c1f4fdc7c724ea04aecfdf500c4329185f8e3649c915baf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, - "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"}, + "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, + "earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], [], "hexpm", "1b34655872366414f69dd987cb121c049f76984b6ac69f52fff6d8fd64d29cfd"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"}, + "ecto": {:hex, :ecto, "3.11.2", "e1d26be989db350a633667c5cda9c3d115ae779b66da567c68c80cfb26a8c9ee", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3c38bca2c6f8d8023f2145326cc8a80100c3ffe4dcbd9842ff867f7fc6156c65"}, + "ex_doc": {:hex, :ex_doc, "0.34.0", "ab95e0775db3df71d30cf8d78728dd9261c355c81382bcd4cefdc74610bef13e", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "60734fb4c1353f270c3286df4a0d51e65a2c1d9fba66af3940847cc65a8066d7"}, + "makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"}, + "makeup_erlang": {:hex, :makeup_erlang, "1.0.0", "6f0eff9c9c489f26b69b61440bf1b238d95badae49adac77973cbacae87e3c2e", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "ea7a9307de9d1548d2a72d299058d1fd2339e3d398560a0e46c27dab4891e4d2"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, + "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm", "8f7168911120e13419e086e78d20e4d1a6776f1eee2411ac9f790af10813389f"}, + "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, } From 5f1fa8c344d4089d9f54289a58e2687e840bb887 Mon Sep 17 00:00:00 2001 From: Corey Powell Date: Wed, 12 Jun 2024 18:38:07 -0500 Subject: [PATCH 3/5] Repo needs an init function Hopefully this shim does what we need --- test/support/test_repo.exs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/support/test_repo.exs b/test/support/test_repo.exs index fc4b91f..c530da1 100644 --- a/test/support/test_repo.exs +++ b/test/support/test_repo.exs @@ -19,6 +19,12 @@ defmodule EctoFacade.TestAdapter do Supervisor.Spec.worker(Task, [fn -> :timer.sleep(:infinity) end]) end + @impl true + def init(config) do + meta = %{stacktrace: nil} + {:ok, child_spec(config[:repo], config), meta} + end + ## Types def loaders(:binary_id, type), do: [Ecto.UUID, type] From 380112794cb8b8ac2dd1e5c26a8da4235e3f5a1e Mon Sep 17 00:00:00 2001 From: Corey Powell Date: Wed, 12 Jun 2024 18:38:56 -0500 Subject: [PATCH 4/5] __adapter__ is a function, in a project using warnings_as_errors this tiny detail turns a working project into a brick i.e. It won't compile, because of that --- lib/ecto_facade/repo.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ecto_facade/repo.ex b/lib/ecto_facade/repo.ex index 464fe03..08b4965 100644 --- a/lib/ecto_facade/repo.ex +++ b/lib/ecto_facade/repo.ex @@ -56,7 +56,7 @@ defmodule EctoFacade.Repo do defdelegate insert_or_update!(changeset, opts \\ []), to: @master_repo defdelegate delete!(struct, opts \\ []), to: @master_repo - if function_exported?(@master_repo.__adapter__, :transaction, 3) do + if function_exported?(@master_repo.__adapter__(), :transaction, 3) do defdelegate transaction(fun_or_multi, opts \\ []), to: @master_repo defdelegate in_transaction?(), to: @master_repo defdelegate rollback(value), to: @master_repo From 2d63062a9e0913a4ea6714cb14ef24d604bf9e36 Mon Sep 17 00:00:00 2001 From: Corey Powell Date: Wed, 12 Jun 2024 18:39:43 -0500 Subject: [PATCH 5/5] Add some of the missing functions from ecto into the facade * reload/2 * reload!/2 * exists?/2 --- lib/ecto_facade/repo.ex | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/ecto_facade/repo.ex b/lib/ecto_facade/repo.ex index 08b4965..c5450e8 100644 --- a/lib/ecto_facade/repo.ex +++ b/lib/ecto_facade/repo.ex @@ -113,6 +113,22 @@ defmodule EctoFacade.Repo do end end + def reload(queryable, opts \\ []) do + try do + get_read_repo().reload(queryable, opts) + catch + _ -> @master_repo.reload(queryable, opts) + end + end + + def reload!(queryable, opts \\ []) do + try do + get_read_repo().reload!(queryable, opts) + catch + _ -> @master_repo.reload!(queryable, opts) + end + end + def one(queryable, opts \\ []) do try do get_read_repo().one(queryable, opts) @@ -138,6 +154,14 @@ defmodule EctoFacade.Repo do end end + def exists?(queryable, opts \\ []) do + try do + get_read_repo().exists?(queryable, opts) + catch + _ -> @master_repo.exists?(queryable, opts) + end + end + def preload(struct_or_structs_or_nil, preloads, opts \\ []) do try do get_read_repo().preload(struct_or_structs_or_nil, preloads, opts) @@ -170,6 +194,10 @@ defmodule EctoFacade.Repo do def get_by!(queryable, clauses, opts \\ []), do: get_read_repo().get_by!(queryable, clauses, opts) + def reload(queryable, opts \\ []), do: get_read_repo().reload(queryable, opts) + + def reload!(queryable, opts \\ []), do: get_read_repo().reload!(queryable, opts) + def one(queryable, opts \\ []), do: get_read_repo().one(queryable, opts) def one!(queryable, opts \\ []), do: get_read_repo().one!(queryable, opts) @@ -179,6 +207,10 @@ defmodule EctoFacade.Repo do get_read_repo().aggregate(queryable, aggregate, field, opts) end + def exists?(queryable, opts \\ []) do + get_read_repo().exists?(queryable, opts) + end + def preload(struct_or_structs_or_nil, preloads, opts \\ []) do get_read_repo().preload(struct_or_structs_or_nil, preloads, opts) end