Skip to content

Commit

Permalink
improvement: honor :priv in migration generator, and make it explic…
Browse files Browse the repository at this point in the history
…itly configurable

closes #426
  • Loading branch information
zachdaniel committed Nov 25, 2024
1 parent 05d417c commit 0bfc8b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/migration_generator/migration_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,15 @@ defmodule AshPostgres.MigrationGenerator do
# Copied from ecto's mix task, thanks Ecto ❤️
config = repo.config()

app = Keyword.fetch!(config, :otp_app)
Path.join([Mix.Project.deps_paths()[app] || File.cwd!(), "priv", "resource_snapshots"])
if snapshot_path = opts[:snapshots_path] do
snapshot_path
else
priv =
config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"

app = Keyword.fetch!(config, :otp_app)
Application.app_dir(app, Path.join(priv, "resource_snapshots"))
end
end

defp create_extension_migrations(repos, opts) do
Expand Down
9 changes: 9 additions & 0 deletions lib/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ defmodule AshPostgres.Repo do
```elixir
%{type: :create, %{resource: YourApp.YourResource, action: :action}}
```
## Additional Repo Configuration
Because an `AshPostgres.Repo` is also an `Ecto.Repo`, it has all of the same callbacks.
In the `c:Ecto.Repo.config/0` callback, you can configure the following additional items:
- `:tenant_migrations_path` - The path where your tenant migrations are stored (only relevant for a multitenant implementation)
- `:snapshots_path` - The path where the resource snapshots for the migration generator are stored.
"""

@doc "Use this to inform the data layer about what extensions are installed"
Expand Down

0 comments on commit 0bfc8b8

Please sign in to comment.