From 0bfc8b87ec49f17d0af12ebfdeee9b0e63854982 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Mon, 25 Nov 2024 12:38:56 -0500 Subject: [PATCH] improvement: honor `:priv` in migration generator, and make it explicitly configurable closes #426 --- lib/migration_generator/migration_generator.ex | 11 +++++++++-- lib/repo.ex | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/migration_generator/migration_generator.ex b/lib/migration_generator/migration_generator.ex index 779538e7..112fb321 100644 --- a/lib/migration_generator/migration_generator.ex +++ b/lib/migration_generator/migration_generator.ex @@ -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 diff --git a/lib/repo.ex b/lib/repo.ex index 5cc66e8d..6f77f300 100644 --- a/lib/repo.ex +++ b/lib/repo.ex @@ -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"