Skip to content

Commit 2655ddc

Browse files
fix: ensure tenant prefix is set only for resources with context multitenancy (#600)
This fixes attribute multitenancy which is currently broken by this commit 60ab568 I thought updating set_tenant is the proper way to do it since it currently just adds the prefix to the query which only makes sense in context multitenancy Maybe attribute multitenancy can be handled there too? .. by adding a filter or something, but it currently seems to be handled somewhere else (not sure where) but I see the multitennacy attribute filter is added to my update queries. * chore: format
1 parent 7b6bf1d commit 2655ddc

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/data_layer.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,12 @@ defmodule AshPostgres.DataLayer do
893893
end
894894

895895
@impl true
896-
def set_tenant(_resource, query, tenant) do
897-
{:ok, Map.put(Ecto.Query.put_query_prefix(query, to_string(tenant)), :__tenant__, tenant)}
896+
def set_tenant(resource, query, tenant) do
897+
if Ash.Resource.Info.multitenancy_strategy(resource) == :context do
898+
{:ok, Map.put(Ecto.Query.put_query_prefix(query, to_string(tenant)), :__tenant__, tenant)}
899+
else
900+
{:ok, query}
901+
end
898902
end
899903

900904
@impl true

lib/migration_generator/migration_generator.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,9 +2037,12 @@ defmodule AshPostgres.MigrationGenerator do
20372037
| acc
20382038
])
20392039
else
2040-
unless opts.quiet do
2041-
Logger.info("Skipping migration for empty resource: #{snapshot.table} (no attributes, identities, indexes, statements, or constraints)")
2040+
if !opts.quiet do
2041+
Logger.info(
2042+
"Skipping migration for empty resource: #{snapshot.table} (no attributes, identities, indexes, statements, or constraints)"
2043+
)
20422044
end
2045+
20432046
acc
20442047
end
20452048
end

0 commit comments

Comments
 (0)