Skip to content

Commit

Permalink
fix: don't use symlinked app dir for migration's path
Browse files Browse the repository at this point in the history
fixes #452
  • Loading branch information
zachdaniel committed Jan 2, 2025
1 parent 304a896 commit a5f6de7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/data_layer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,7 @@ defmodule AshPostgres.DataLayer do

fields_to_upsert =
upsert_fields --
Keyword.keys(Enum.at(changesets, 0).atomics) -- keys
(Keyword.keys(Enum.at(changesets, 0).atomics) -- keys)

fields_to_upsert =
case fields_to_upsert do
Expand Down
15 changes: 5 additions & 10 deletions lib/migration_generator/migration_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,7 @@ defmodule AshPostgres.MigrationGenerator do
snapshot_path
else
app = Keyword.fetch!(config, :otp_app)

Application.app_dir(
app,
["priv", "resource_snapshots"]
)
Path.join(Mix.Project.deps_paths()[app] || File.cwd!(), "priv/resource_snapshots")
end
end

Expand Down Expand Up @@ -889,25 +885,24 @@ defmodule AshPostgres.MigrationGenerator do
defp migration_path(opts, repo, tenant? \\ false) do
# Copied from ecto's mix task, thanks Ecto ❤️
config = repo.config()
app = Keyword.fetch!(config, :otp_app)

if tenant? do
if path = opts.tenant_migration_path || config[:tenant_migrations_path] do
path
else
priv =
config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
AshPostgres.Mix.Helpers.source_repo_priv(repo)

Application.app_dir(app, Path.join(priv, "tenant_migrations"))
Path.join(priv, "tenant_migrations")
end
else
if path = opts.migration_path || config[:tenant_migrations_path] do
path
else
priv =
config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
AshPostgres.Mix.Helpers.source_repo_priv(repo)

Application.app_dir(app, Path.join(priv, "migrations"))
Path.join(priv, "migrations")
end
end
end
Expand Down
13 changes: 8 additions & 5 deletions lib/mix/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,19 @@ defmodule AshPostgres.Mix.Helpers do
end

def derive_migrations_path(repo) do
config = repo.config()
priv = config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
app = Keyword.fetch!(config, :otp_app)
Application.app_dir(app, Path.join(priv, "migrations"))
priv = source_repo_priv(repo)
Path.join(priv, "migrations")
end

def derive_tenant_migrations_path(repo) do
priv = source_repo_priv(repo)
Path.join(priv, "tenant_migrations")
end

def source_repo_priv(repo) do
config = repo.config()
priv = config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
app = Keyword.fetch!(config, :otp_app)
Application.app_dir(app, Path.join(priv, "tenant_migrations"))
Path.join(Mix.Project.deps_paths()[app] || File.cwd!(), priv)
end
end

0 comments on commit a5f6de7

Please sign in to comment.