diff --git a/lib/migration_generator/migration_generator.ex b/lib/migration_generator/migration_generator.ex index 7a7a0005..7ce9edab 100644 --- a/lib/migration_generator/migration_generator.ex +++ b/lib/migration_generator/migration_generator.ex @@ -865,27 +865,28 @@ defmodule AshPostgres.MigrationGenerator do end defp migration_path(opts, repo, tenant? \\ false) do - repo_name = repo_name(repo) # Copied from ecto's mix task, thanks Ecto ❤️ config = repo.config() app = Keyword.fetch!(config, :otp_app) if tenant? do - if opts.tenant_migration_path do - opts.tenant_migration_path + if path = opts.tenant_migration_path || config[:tenant_migrations_path] do + path else - Path.join([Mix.Project.deps_paths()[app] || File.cwd!(), "priv"]) + priv = + config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}" + + Application.app_dir(app, Path.join(priv, "tenant_migrations")) end - |> Path.join(repo_name) - |> Path.join("tenant_migrations") else - if opts.migration_path do - opts.migration_path + if path = opts.migration_path || config[:tenant_migrations_path] do + path else - Path.join([Mix.Project.deps_paths()[app] || File.cwd!(), "priv"]) + priv = + config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}" + + Application.app_dir(app, Path.join(priv, "migrations")) end - |> Path.join(repo_name) - |> Path.join("migrations") end end diff --git a/lib/mix/tasks/ash_postgres.generate_migrations.ex b/lib/mix/tasks/ash_postgres.generate_migrations.ex index 08f46528..b71568d4 100644 --- a/lib/mix/tasks/ash_postgres.generate_migrations.ex +++ b/lib/mix/tasks/ash_postgres.generate_migrations.ex @@ -5,10 +5,10 @@ defmodule Mix.Tasks.AshPostgres.GenerateMigrations do Options: * `domains` - a comma separated list of Domain modules, for which migrations will be generated - * `snapshot-path` - a custom path to store the snapshots, defaults to "priv/resource_snapshots" - * `migration-path` - a custom path to store the migrations, defaults to "priv". + * `snapshot-path` - a custom path to store the snapshots, defaults to "priv/repo_name/resource_snapshots" + * `migration-path` - a custom path to store the migrations, defaults to "priv/repo_name/migrations". Migrations are stored in a folder for each repo, so `priv/repo_name/migrations` - * `tenant-migration-path` - Same as `migration_path`, except for any tenant specific migrations + * `tenant-migration-path` - Same as `migration_path`, except for tenant-specific migrations * `drop-columns` - whether or not to drop columns as attributes are removed. See below for more * `name` - names the generated migrations, prepending with the timestamp. The default is `migrate_resources_`, diff --git a/lib/repo.ex b/lib/repo.ex index 6f77f300..5429fdf6 100644 --- a/lib/repo.ex +++ b/lib/repo.ex @@ -44,7 +44,7 @@ defmodule AshPostgres.Repo do 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: + In the `c:Ecto.Repo.init/2` 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.