Skip to content

Commit 17abe38

Browse files
committed
improvement: honor repo configuration in migration generator
1 parent 9eef1f4 commit 17abe38

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

lib/migration_generator/migration_generator.ex

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -865,27 +865,28 @@ defmodule AshPostgres.MigrationGenerator do
865865
end
866866

867867
defp migration_path(opts, repo, tenant? \\ false) do
868-
repo_name = repo_name(repo)
869868
# Copied from ecto's mix task, thanks Ecto ❤️
870869
config = repo.config()
871870
app = Keyword.fetch!(config, :otp_app)
872871

873872
if tenant? do
874-
if opts.tenant_migration_path do
875-
opts.tenant_migration_path
873+
if path = opts.tenant_migration_path || config[:tenant_migrations_path] do
874+
path
876875
else
877-
Path.join([Mix.Project.deps_paths()[app] || File.cwd!(), "priv"])
876+
priv =
877+
config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
878+
879+
Application.app_dir(app, Path.join(priv, "tenant_migrations"))
878880
end
879-
|> Path.join(repo_name)
880-
|> Path.join("tenant_migrations")
881881
else
882-
if opts.migration_path do
883-
opts.migration_path
882+
if path = opts.migration_path || config[:tenant_migrations_path] do
883+
path
884884
else
885-
Path.join([Mix.Project.deps_paths()[app] || File.cwd!(), "priv"])
885+
priv =
886+
config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
887+
888+
Application.app_dir(app, Path.join(priv, "migrations"))
886889
end
887-
|> Path.join(repo_name)
888-
|> Path.join("migrations")
889890
end
890891
end
891892

lib/mix/tasks/ash_postgres.generate_migrations.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ defmodule Mix.Tasks.AshPostgres.GenerateMigrations do
55
Options:
66
77
* `domains` - a comma separated list of Domain modules, for which migrations will be generated
8-
* `snapshot-path` - a custom path to store the snapshots, defaults to "priv/resource_snapshots"
9-
* `migration-path` - a custom path to store the migrations, defaults to "priv".
8+
* `snapshot-path` - a custom path to store the snapshots, defaults to "priv/repo_name/resource_snapshots"
9+
* `migration-path` - a custom path to store the migrations, defaults to "priv/repo_name/migrations".
1010
Migrations are stored in a folder for each repo, so `priv/repo_name/migrations`
11-
* `tenant-migration-path` - Same as `migration_path`, except for any tenant specific migrations
11+
* `tenant-migration-path` - Same as `migration_path`, except for tenant-specific migrations
1212
* `drop-columns` - whether or not to drop columns as attributes are removed. See below for more
1313
* `name` -
1414
names the generated migrations, prepending with the timestamp. The default is `migrate_resources_<n>`,

lib/repo.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ defmodule AshPostgres.Repo do
4444
4545
Because an `AshPostgres.Repo` is also an `Ecto.Repo`, it has all of the same callbacks.
4646
47-
In the `c:Ecto.Repo.config/0` callback, you can configure the following additional items:
47+
In the `c:Ecto.Repo.init/2` callback, you can configure the following additional items:
4848
4949
- `:tenant_migrations_path` - The path where your tenant migrations are stored (only relevant for a multitenant implementation)
5050
- `:snapshots_path` - The path where the resource snapshots for the migration generator are stored.

0 commit comments

Comments
 (0)