mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 05:23:18 +12:00
fix: properly turn custom index keys into atoms
improvement: support new transaction info with hooks
This commit is contained in:
parent
059837651d
commit
c035eed21a
3 changed files with 24 additions and 12 deletions
|
@ -59,6 +59,7 @@ defmodule AshPostgres.CustomIndex do
|
|||
|
||||
# sobelow_skip ["DOS.StringToAtom"]
|
||||
def transform(%__MODULE__{fields: fields} = index) do
|
||||
{:ok,
|
||||
%{
|
||||
index
|
||||
| fields:
|
||||
|
@ -69,7 +70,7 @@ defmodule AshPostgres.CustomIndex do
|
|||
String.to_atom(field)
|
||||
end
|
||||
end)
|
||||
}
|
||||
}}
|
||||
end
|
||||
|
||||
def name(_resource, %{name: name}) when is_binary(name) do
|
||||
|
|
|
@ -52,6 +52,7 @@ defmodule AshPostgres.DataLayer do
|
|||
],
|
||||
target: AshPostgres.CustomIndex,
|
||||
schema: AshPostgres.CustomIndex.schema(),
|
||||
transform: {AshPostgres.CustomIndex, :transform, []},
|
||||
args: [:fields]
|
||||
}
|
||||
|
||||
|
@ -1633,7 +1634,12 @@ defmodule AshPostgres.DataLayer do
|
|||
end
|
||||
|
||||
@impl true
|
||||
def transaction(resource, func, timeout \\ nil) do
|
||||
def transaction(resource, func, timeout \\ nil, reason \\ %{type: :custom, metadata: %{}}) do
|
||||
func = fn ->
|
||||
AshPostgres.DataLayer.Info.repo(resource).on_transaction_begin(reason)
|
||||
func.()
|
||||
end
|
||||
|
||||
if timeout do
|
||||
AshPostgres.DataLayer.Info.repo(resource).transaction(func, timeout: timeout)
|
||||
else
|
||||
|
|
|
@ -37,6 +37,8 @@ defmodule AshPostgres.Repo do
|
|||
"""
|
||||
@callback min_pg_version() :: integer()
|
||||
|
||||
@callback on_transaction_begin(reason :: Ash.DataLayer.transaction_reason()) :: term
|
||||
|
||||
@doc "Return a list of all schema names (only relevant for a multitenant implementation)"
|
||||
@callback all_tenants() :: [String.t()]
|
||||
@doc "The path where your tenant migrations are stored (only relevant for a multitenant implementation)"
|
||||
|
@ -87,7 +89,10 @@ defmodule AshPostgres.Repo do
|
|||
{:ok, new_config}
|
||||
end
|
||||
|
||||
def on_transaction_begin(_reason), do: :ok
|
||||
|
||||
defoverridable init: 2,
|
||||
on_transaction_begin: 1,
|
||||
installed_extensions: 0,
|
||||
all_tenants: 0,
|
||||
tenant_migrations_path: 0,
|
||||
|
|
Loading…
Reference in a new issue