Skip to content

Commit 87820a5

Browse files
authored
fix: add tenant to ash bindings in update (#534)
1 parent 74439d5 commit 87820a5

File tree

4 files changed

+47
-40
lines changed

4 files changed

+47
-40
lines changed

lib/data_layer.ex

+7
Original file line numberDiff line numberDiff line change
@@ -3073,6 +3073,13 @@ defmodule AshPostgres.DataLayer do
30733073
changeset.context
30743074
)
30753075
|> pkey_filter(changeset.data)
3076+
|> then(fn query ->
3077+
Map.put(
3078+
query,
3079+
:__ash_bindings__,
3080+
Map.put_new(query.__ash_bindings__, :tenant, changeset.tenant)
3081+
)
3082+
end)
30763083

30773084
changeset =
30783085
Ash.Changeset.set_context(changeset, %{

mix.exs

+15-16
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ defmodule AshPostgres.MixProject do
167167
defp deps do
168168
[
169169
{:ash, ash_version("~> 3.4 and >= 3.4.69")},
170-
# {:ash_sql, ash_sql_version("~> 0.2 and >= 0.2.68")},
171-
{:ash_sql, github: "ash-project/ash_sql"},
170+
{:ash_sql, ash_sql_version("~> 0.2 and >= 0.2.72")},
172171
{:igniter, "~> 0.5 and >= 0.5.16", optional: true},
173172
{:ecto_sql, "~> 3.12"},
174173
{:ecto, "~> 3.12 and >= 3.12.1"},
@@ -209,24 +208,24 @@ defmodule AshPostgres.MixProject do
209208
end
210209
end
211210

212-
# defp ash_sql_version(default_version) do
213-
# case System.get_env("ASH_SQL_VERSION") do
214-
# nil ->
215-
# default_version
211+
defp ash_sql_version(default_version) do
212+
case System.get_env("ASH_SQL_VERSION") do
213+
nil ->
214+
default_version
216215

217-
# "local" ->
218-
# [path: "../ash_sql", override: true]
216+
"local" ->
217+
[path: "../ash_sql", override: true]
219218

220-
# "main" ->
221-
# [git: "https://github.com/ash-project/ash_sql.git"]
219+
"main" ->
220+
[git: "https://github.com/ash-project/ash_sql.git"]
222221

223-
# version when is_binary(version) ->
224-
# "~> #{version}"
222+
version when is_binary(version) ->
223+
"~> #{version}"
225224

226-
# version ->
227-
# version
228-
# end
229-
# end
225+
version ->
226+
version
227+
end
228+
end
230229

231230
defp aliases do
232231
[

mix.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%{
22
"ash": {:hex, :ash, "3.5.6", "2f187150110b4c280c8551ad411f56d95862fcb37c067a0b8b94eb682bcc43e8", [: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.5.24 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {: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.11", [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.6 and < 1.0.0-0", [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", "d0d9aeb5aacfdc12253fae1e7e4720991868c5f69632c2766afb03b2b1830f55"},
3+
"ash_sql": {:hex, :ash_sql, "0.2.72", "3c353fd3361257310864dce131acd93e407379439cf8667d7ddb4cba99a3fe2c", [:mix], [{:ash, "~> 3.5", [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", "0a802299580b8406258f9d72ec8c2a39b4d4b9ad49a2631d47a15d3290d7b0eb"},
34
"benchee": {:hex, :benchee, "1.4.0", "9f1f96a30ac80bab94faad644b39a9031d5632e517416a8ab0a6b0ac4df124ce", [: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", "299cd10dd8ce51c9ea3ddb74bb150f93d25e968f93e4c1fa31698a8e4fa5d715"},
4-
"ash_sql": {:git, "https://github.com/ash-project/ash_sql.git", "91d990700d18055759004a60cc35f3074da3d1a9", []},
55
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
66
"credo": {:hex, :credo, "1.7.12", "9e3c20463de4b5f3f23721527fcaf16722ec815e70ff6c60b86412c695d426c1", [: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", "8493d45c656c5427d9c729235b99d498bd133421f3e0a683e5c1b561471291e5"},
77
"db_connection": {:hex, :db_connection, "2.7.0", "b99faa9291bb09892c7da373bb82cba59aefa9b36300f6145c5f201c7adf48ec", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "dcf08f31b2701f857dfc787fbad78223d61a32204f217f15e881dd93e4bdd3ff"},

test/atomics_test.exs

+24-23
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ defmodule AshPostgres.AtomicsTest do
33
alias AshPostgres.Test.Comment
44

55
use AshPostgres.RepoCase, async: false
6+
67
alias AshPostgres.Test.Invite
78
alias AshPostgres.Test.Post
89
alias AshPostgres.Test.User
@@ -367,29 +368,29 @@ defmodule AshPostgres.AtomicsTest do
367368
|> Ash.update!()
368369
end
369370

370-
# assert_raise Ash.Error.Invalid, ~r/Can only update if Post has no comments/, fn ->
371-
# post
372-
# |> Ash.Changeset.new()
373-
# |> Ash.Changeset.put_context(:aggregate, unquote(aggregate))
374-
# |> Ash.Changeset.for_update(:update_if_no_comments_non_atomic, %{title: "bar"})
375-
# |> Ash.update!()
376-
# end
377-
378-
# assert_raise Ash.Error.Invalid, ~r/Can only delete if Post has no comments/, fn ->
379-
# post
380-
# |> Ash.Changeset.new()
381-
# |> Ash.Changeset.put_context(:aggregate, unquote(aggregate))
382-
# |> Ash.Changeset.for_destroy(:destroy_if_no_comments_non_atomic, %{})
383-
# |> Ash.destroy!()
384-
# end
385-
386-
# assert_raise Ash.Error.Invalid, ~r/Can only delete if Post has no comments/, fn ->
387-
# post
388-
# |> Ash.Changeset.new()
389-
# |> Ash.Changeset.put_context(:aggregate, unquote(aggregate))
390-
# |> Ash.Changeset.for_destroy(:destroy_if_no_comments, %{})
391-
# |> Ash.destroy!()
392-
# end
371+
assert_raise Ash.Error.Invalid, ~r/Can only update if Post has no comments/, fn ->
372+
post
373+
|> Ash.Changeset.new()
374+
|> Ash.Changeset.put_context(:aggregate, unquote(aggregate))
375+
|> Ash.Changeset.for_update(:update_if_no_comments_non_atomic, %{title: "bar"})
376+
|> Ash.update!()
377+
end
378+
379+
assert_raise Ash.Error.Invalid, ~r/Can only delete if Post has no comments/, fn ->
380+
post
381+
|> Ash.Changeset.new()
382+
|> Ash.Changeset.put_context(:aggregate, unquote(aggregate))
383+
|> Ash.Changeset.for_destroy(:destroy_if_no_comments_non_atomic, %{})
384+
|> Ash.destroy!()
385+
end
386+
387+
assert_raise Ash.Error.Invalid, ~r/Can only delete if Post has no comments/, fn ->
388+
post
389+
|> Ash.Changeset.new()
390+
|> Ash.Changeset.put_context(:aggregate, unquote(aggregate))
391+
|> Ash.Changeset.for_destroy(:destroy_if_no_comments, %{})
392+
|> Ash.destroy!()
393+
end
393394
end
394395
end
395396
)

0 commit comments

Comments
 (0)