From aeb77ded27a58de597fc76ac964b1ee48a8f1729 Mon Sep 17 00:00:00 2001 From: Sean Brennan <102389629+sean-regents@users.noreply.github.com> Date: Mon, 26 Oct 2026 15:24:43 -0400 Subject: [PATCH] fix: upserts and merges use the repo's default prefix AshPostgres.Upsert and AshPostgres.Merge build their SQL by hand and took the schema only from opts[:prefix], which is set from the resource's own schema or the tenant. A repo that chooses its schema through default_options/1 had every upsert written to "public" instead, unlike repo.insert_all/3, which applies those options. Both now fall back to repo.default_options(:insert_all)[:prefix]. --- lib/merge.ex | 2 +- lib/upsert.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/merge.ex b/lib/merge.ex index 68e19af4..2f414864 100644 --- a/lib/merge.ex +++ b/lib/merge.ex @@ -87,7 +87,7 @@ defmodule AshPostgres.Merge do defp do_merge(repo, resource, entries, opts) do table = Keyword.fetch!(opts, :table) - prefix = opts[:prefix] + prefix = opts[:prefix] || repo.default_options(:insert_all)[:prefix] # 1. USING (VALUES ...) AS EXCLUDED(cols) -- rendered, dumped, and cast by Ecto. {values_sql, values_params} = diff --git a/lib/upsert.ex b/lib/upsert.ex index fd2825f1..a4bcdefb 100644 --- a/lib/upsert.ex +++ b/lib/upsert.ex @@ -74,7 +74,7 @@ defmodule AshPostgres.Upsert do defp do_insert_all(repo, resource, entries, opts) do table = Keyword.fetch!(opts, :table) - prefix = opts[:prefix] + prefix = opts[:prefix] || repo.default_options(:insert_all)[:prefix] # 1. (cols) VALUES ($1, $2, DEFAULT), ... -- values dumped through the resource's Ecto schema. {header, values_sql, values_params, counter} = build_values(repo, resource, entries)