Skip to content

Commit

Permalink
improvement: adapt to fixes and optimizations around skipped upserts …
Browse files Browse the repository at this point in the history
…in ash core

test: update tests correspondingly
  • Loading branch information
zachdaniel committed Oct 10, 2024
1 parent c5c9575 commit bd91615
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions lib/data_layer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2588,10 +2588,14 @@ defmodule AshPostgres.DataLayer do
end)
|> Ash.Query.set_tenant(changeset.tenant)

with {:ok, ecto_query} <- Ash.Query.data_layer_query(ash_query),
{:ok, [result]} <- run_query(ecto_query, resource) do
{:ok, Ash.Resource.put_metadata(result, :upsert_skipped, true)}
end
{:ok,
{:upsert_skipped, ash_query,
fn ->
with {:ok, ecto_query} <- Ash.Query.data_layer_query(ash_query),
{:ok, [result]} <- run_query(ecto_query, resource) do
{:ok, Ash.Resource.put_metadata(result, :upsert_skipped, true)}
end
end}}

{:ok, [result]} ->
{:ok, result}
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ defmodule AshPostgres.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:ash, ash_version("~> 3.4 and >= 3.4.9")},
{:ash, ash_version("~> 3.4 and >= 3.4.28")},
{:ash_sql, ash_sql_version("~> 0.2 and >= 0.2.30")},
{:igniter, "~> 0.3 and >= 0.3.42"},
{:ecto_sql, "~> 3.12"},
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%{
"ash": {:hex, :ash, "3.4.27", "8a7f8102a053c5238654a1089bbd6330f400386eb5ef5201755b6332fc4c7566", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:igniter, ">= 0.3.36 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:owl, "~> 0.11", [hex: :owl, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, "~> 0.9", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.2.29 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.2", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "55d2c70f23b51bc97abb414729ced315995f502f98e8cbfad2298c2ed083b8c9"},
"ash_sql": {:hex, :ash_sql, "0.2.36", "e5722123de5b726ad3185ef8c8ce5ef17b78d3409e822cadeadc6ba5110601fe", [:mix], [{:ash, ">= 3.1.7 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.9", [hex: :ecto_sql, repo: "hexpm", optional: false]}], "hexpm", "a95b5ebccfe5e74d7fc4e46b104abae4d1003b53cbc8418fcb5fa3c6e0c081a9"},
"ash": {:hex, :ash, "3.4.28", "499c8cf49e406cc5a9b7c6e8e0daae616d2cbd5a02ad421db7932b2972e8badf", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:igniter, ">= 0.3.36 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:owl, "~> 0.11", [hex: :owl, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, "~> 0.9", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.2.29 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.2", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7faafca1f6b70bf2e72dbabef0d667ee2108923df465878e94f03b2ea8c24fe8"},
"benchee": {:hex, :benchee, "1.3.1", "c786e6a76321121a44229dde3988fc772bca73ea75170a73fd5f4ddf1af95ccf", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "76224c58ea1d0391c8309a8ecbfe27d71062878f59bd41a390266bf4ac1cc56d"},
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"credo": {:hex, :credo, "1.7.8", "9722ba1681e973025908d542ec3d95db5f9c549251ba5b028e251ad8c24ab8c5", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "cb9e87cc64f152f3ed1c6e325e7b894dea8f5ef2e41123bd864e3cd5ceb44968"},
Expand Down
2 changes: 1 addition & 1 deletion test/create_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule AshPostgres.CreateTest do
uniq_if_contains_foo: "foo",
price: 10
})
|> Ash.create()
|> Ash.create(return_skipped_upsert?: true)

assert Ash.Resource.get_metadata(post, :upsert_skipped)
end
Expand Down

0 comments on commit bd91615

Please sign in to comment.