Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions lib/migration_generator/migration_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3109,11 +3109,39 @@ defmodule AshPostgres.MigrationGenerator do
not is_nil(Map.get(attribute, :references)) and
!(attribute.references.multitenancy &&
attribute.references.multitenancy.strategy == :context &&
(is_nil(multitenancy) || multitenancy.strategy == :attribute))
(is_nil(multitenancy) || multitenancy.strategy == :attribute)) and
!(multitenancy && multitenancy.strategy == :context &&
attribute.references.multitenancy &&
attribute.references.multitenancy.strategy == :context)
end

def get_existing_snapshot(snapshot, opts) do
folder = get_snapshot_folder(snapshot, opts)
defp get_snapshot_folder(snapshot, opts) do
base =
opts
|> snapshot_path(snapshot.repo)
|> Path.join(repo_name(snapshot.repo))

if snapshot.multitenancy.strategy == :context do
Path.join(base, "tenants")
else
base
end
end

defp get_alternate_snapshot_folder(snapshot, opts) do
base =
opts
|> snapshot_path(snapshot.repo)
|> Path.join(repo_name(snapshot.repo))

if snapshot.multitenancy.strategy == :context do
base
else
Path.join(base, "tenants")
end
end

defp load_snapshot_from_folder(folder, snapshot, opts) do
snapshot_path = get_snapshot_path(snapshot, folder)

if File.exists?(snapshot_path) do
Expand All @@ -3138,16 +3166,13 @@ defmodule AshPostgres.MigrationGenerator do
end
end

defp get_snapshot_folder(snapshot, opts) do
if snapshot.multitenancy.strategy == :context do
opts
|> snapshot_path(snapshot.repo)
|> Path.join(repo_name(snapshot.repo))
|> Path.join("tenants")
def get_existing_snapshot(snapshot, opts) do
result = load_snapshot_from_folder(get_snapshot_folder(snapshot, opts), snapshot, opts)

if is_nil(result) do
load_snapshot_from_folder(get_alternate_snapshot_folder(snapshot, opts), snapshot, opts)
else
opts
|> snapshot_path(snapshot.repo)
|> Path.join(repo_name(snapshot.repo))
result
end
end

Expand Down