Skip to content

Commit 0f38bf2

Browse files
authored
feat: add repo callback to disable atomic actions and error expressions (#464)
1 parent bb9bd5b commit 0f38bf2

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

lib/data_layer.ex

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,11 @@ defmodule AshPostgres.DataLayer do
644644
def can?(_, :transact), do: true
645645
def can?(_, :composite_primary_key), do: true
646646

647-
def can?(_resource, {:atomic, :update}), do: true
648-
def can?(_resource, {:atomic, :upsert}), do: true
647+
def can?(resource, {:atomic, :update}),
648+
do: not AshPostgres.DataLayer.Info.repo(resource, :mutate).disable_atomic_actions?()
649+
650+
def can?(resource, {:atomic, :upsert}),
651+
do: not AshPostgres.DataLayer.Info.repo(resource, :mutate).disable_atomic_actions?()
649652

650653
def can?(_, :upsert), do: true
651654
def can?(_, :changeset_filter), do: true
@@ -709,10 +712,13 @@ defmodule AshPostgres.DataLayer do
709712
def can?(_, {:aggregate_relationship, _}), do: true
710713

711714
def can?(_, :timeout), do: true
712-
def can?(_, :expr_error), do: true
715+
716+
def can?(resource, :expr_error),
717+
do: not AshPostgres.DataLayer.Info.repo(resource, :mutate).disable_expr_error?()
713718

714719
def can?(resource, {:filter_expr, %Ash.Query.Function.Error{}}) do
715-
"ash-functions" in AshPostgres.DataLayer.Info.repo(resource, :read).installed_extensions() &&
720+
not AshPostgres.DataLayer.Info.repo(resource, :mutate).disable_expr_error?() &&
721+
"ash-functions" in AshPostgres.DataLayer.Info.repo(resource, :read).installed_extensions() &&
716722
"ash-functions" in AshPostgres.DataLayer.Info.repo(resource, :mutate).installed_extensions()
717723
end
718724

lib/repo.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ defmodule AshPostgres.Repo do
104104
@doc "Should the repo should be dropped by `mix ash_postgres.drop`?"
105105
@callback drop?() :: boolean
106106

107+
@doc "Disable atomic actions for this repo"
108+
@callback disable_atomic_actions?() :: boolean
109+
110+
@doc "Disable expression errors for this repo"
111+
@callback disable_expr_error?() :: boolean
112+
107113
defmacro __using__(opts) do
108114
quote bind_quoted: [opts: opts] do
109115
if Keyword.get(opts, :define_ecto_repo?, true) do
@@ -133,6 +139,8 @@ defmodule AshPostgres.Repo do
133139
def override_migration_type(type), do: type
134140
def create?, do: true
135141
def drop?, do: true
142+
def disable_atomic_actions?, do: false
143+
def disable_expr_error?, do: false
136144

137145
# default to false in 4.0
138146
def prefer_transaction?, do: true
@@ -288,7 +296,9 @@ defmodule AshPostgres.Repo do
288296
default_prefix: 0,
289297
override_migration_type: 1,
290298
create?: 0,
291-
drop?: 0
299+
drop?: 0,
300+
disable_atomic_actions?: 0,
301+
disable_expr_error?: 0
292302

293303
# We do this switch because `!@warn_on_missing_ash_functions` in the function body triggers
294304
# a dialyzer error

0 commit comments

Comments
 (0)