Skip to content

Commit a5f6de7

Browse files
committed
fix: don't use symlinked app dir for migration's path
fixes #452
1 parent 304a896 commit a5f6de7

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

lib/data_layer.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1963,7 +1963,7 @@ defmodule AshPostgres.DataLayer do
19631963

19641964
fields_to_upsert =
19651965
upsert_fields --
1966-
Keyword.keys(Enum.at(changesets, 0).atomics) -- keys
1966+
(Keyword.keys(Enum.at(changesets, 0).atomics) -- keys)
19671967

19681968
fields_to_upsert =
19691969
case fields_to_upsert do

lib/migration_generator/migration_generator.ex

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,7 @@ defmodule AshPostgres.MigrationGenerator do
157157
snapshot_path
158158
else
159159
app = Keyword.fetch!(config, :otp_app)
160-
161-
Application.app_dir(
162-
app,
163-
["priv", "resource_snapshots"]
164-
)
160+
Path.join(Mix.Project.deps_paths()[app] || File.cwd!(), "priv/resource_snapshots")
165161
end
166162
end
167163

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

894889
if tenant? do
895890
if path = opts.tenant_migration_path || config[:tenant_migrations_path] do
896891
path
897892
else
898893
priv =
899-
config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
894+
AshPostgres.Mix.Helpers.source_repo_priv(repo)
900895

901-
Application.app_dir(app, Path.join(priv, "tenant_migrations"))
896+
Path.join(priv, "tenant_migrations")
902897
end
903898
else
904899
if path = opts.migration_path || config[:tenant_migrations_path] do
905900
path
906901
else
907902
priv =
908-
config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
903+
AshPostgres.Mix.Helpers.source_repo_priv(repo)
909904

910-
Application.app_dir(app, Path.join(priv, "migrations"))
905+
Path.join(priv, "migrations")
911906
end
912907
end
913908
end

lib/mix/helpers.ex

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,19 @@ defmodule AshPostgres.Mix.Helpers do
170170
end
171171

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

179177
def derive_tenant_migrations_path(repo) do
178+
priv = source_repo_priv(repo)
179+
Path.join(priv, "tenant_migrations")
180+
end
181+
182+
def source_repo_priv(repo) do
180183
config = repo.config()
181184
priv = config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
182185
app = Keyword.fetch!(config, :otp_app)
183-
Application.app_dir(app, Path.join(priv, "tenant_migrations"))
186+
Path.join(Mix.Project.deps_paths()[app] || File.cwd!(), priv)
184187
end
185188
end

0 commit comments

Comments
 (0)