Skip to content

Commit e7890be

Browse files
committed
improvement: honor repo configs and add snapshot configs
closes #104
1 parent 9bccc62 commit e7890be

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

lib/migration_generator/migration_generator.ex

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,15 @@ defmodule AshSqlite.MigrationGenerator do
138138
# Copied from ecto's mix task, thanks Ecto ❤️
139139
config = repo.config()
140140

141-
app = Keyword.fetch!(config, :otp_app)
142-
Path.join([Mix.Project.deps_paths()[app] || File.cwd!(), "priv", "resource_snapshots"])
141+
if snapshot_path = config[:snapshots_path] do
142+
snapshot_path
143+
else
144+
priv =
145+
config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
146+
147+
app = Keyword.fetch!(config, :otp_app)
148+
Application.app_dir(app, Path.join(priv, "resource_snapshots"))
149+
end
143150
end
144151

145152
defp create_extension_migrations(repos, opts) do
@@ -655,18 +662,18 @@ defmodule AshSqlite.MigrationGenerator do
655662
end
656663

657664
defp migration_path(opts, repo) do
658-
repo_name = repo_name(repo)
659665
# Copied from ecto's mix task, thanks Ecto ❤️
660666
config = repo.config()
661667
app = Keyword.fetch!(config, :otp_app)
662668

663-
if opts.migration_path do
664-
opts.migration_path
669+
if path = opts.migration_path || config[:tenant_migrations_path] do
670+
path
665671
else
666-
Path.join([Mix.Project.deps_paths()[app] || File.cwd!(), "priv"])
672+
priv =
673+
config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
674+
675+
Application.app_dir(app, Path.join(priv, "migrations"))
667676
end
668-
|> Path.join(repo_name)
669-
|> Path.join("migrations")
670677
end
671678

672679
defp repo_name(repo) do

lib/repo.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ defmodule AshSqlite.Repo do
77
You can use `Ecto.Repo`'s `init/2` to configure your repo like normal, but
88
instead of returning `{:ok, config}`, use `super(config)` to pass the
99
configuration to the `AshSqlite.Repo` implementation.
10+
11+
## Additional Repo Configuration
12+
13+
Because an `AshPostgres.Repo` is also an `Ecto.Repo`, it has all of the same callbacks.
14+
15+
In the `c:Ecto.Repo.init/2` callback, you can configure the following additional items:
16+
17+
- `:tenant_migrations_path` - The path where your tenant migrations are stored (only relevant for a multitenant implementation)
18+
- `:snapshots_path` - The path where the resource snapshots for the migration generator are stored.
1019
"""
1120

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

0 commit comments

Comments
 (0)