diff --git a/lib/igniter.ex b/lib/igniter.ex index 70d190fe..e7f782ad 100644 --- a/lib/igniter.ex +++ b/lib/igniter.ex @@ -12,6 +12,12 @@ defmodule AshPostgres.Igniter do %Version{major: #{min_pg_version.major}, minor: #{min_pg_version.minor}, patch: #{min_pg_version.patch}} end + # Don't open unnecessary transactions + # will default to `false` in 4.0 + def prefer_transaction? do + false + end + def installed_extensions do # Add extensions here, and the migration generator will install them. ["ash-functions"] diff --git a/lib/mix/tasks/ash_postgres.install.ex b/lib/mix/tasks/ash_postgres.install.ex index 280e7f20..12c79266 100644 --- a/lib/mix/tasks/ash_postgres.install.ex +++ b/lib/mix/tasks/ash_postgres.install.ex @@ -368,6 +368,10 @@ defmodule Mix.Tasks.AshPostgres.Install do repo, &configure_installed_extensions_function/1 ) + |> Igniter.Project.Module.find_and_update_module!( + repo, + &configure_prefer_transaction_function/1 + ) |> Igniter.Project.Module.find_and_update_module!( repo, &configure_min_pg_version_function(&1, repo, opts) @@ -443,6 +447,23 @@ defmodule Mix.Tasks.AshPostgres.Install do end end + defp configure_prefer_transaction_function(zipper) do + case Igniter.Code.Function.move_to_def(zipper, :prefer_transaction?, 0) do + {:ok, zipper} -> + {:ok, zipper} + + _ -> + {:ok, + Igniter.Code.Common.add_code(zipper, """ + # Don't open unnecessary transactions + # will default to `false` in 4.0 + def prefer_transaction? do + false + end + """)} + end + end + defp configure_min_pg_version_function(zipper, repo, opts) do case Igniter.Code.Function.move_to_def(zipper, :min_pg_version, 0) do {:ok, zipper} ->