Skip to content

Commit

Permalink
improvement: set prefer_transaction? to false in generated repos
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Oct 27, 2024
1 parent 60ce924 commit 474d804
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/igniter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
21 changes: 21 additions & 0 deletions lib/mix/tasks/ash_postgres.install.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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} ->
Expand Down

0 comments on commit 474d804

Please sign in to comment.