mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-19 21:13:19 +12:00
fix: list_tenants
-> all_tenants
fix: when checking for roll back-able migrations, only check `Path.basename`
This commit is contained in:
parent
6c81699b0d
commit
f0779580b3
1 changed files with 38 additions and 30 deletions
|
@ -447,7 +447,7 @@ defmodule AshPostgres.DataLayer do
|
|||
|> Enum.sort()
|
||||
|> Enum.reverse()
|
||||
|> Enum.filter(fn file ->
|
||||
Enum.any?(current_migrations, &String.starts_with?(file, &1))
|
||||
Enum.any?(current_migrations, &String.starts_with?(Path.basename(file), &1))
|
||||
end)
|
||||
|> Enum.take(20)
|
||||
|> Enum.map(&String.trim_leading(&1, migrations_path))
|
||||
|
@ -484,31 +484,37 @@ defmodule AshPostgres.DataLayer do
|
|||
Mix.Task.run("ash_postgres.rollback", args ++ ["-r", inspect(repo), "-n", to_string(n)])
|
||||
Mix.Task.reenable("ash_postgres.rollback")
|
||||
|
||||
first_tenant = repo.list_tenants() |> Enum.at(0)
|
||||
tenant_files =
|
||||
tenant_migrations_path
|
||||
|> Path.join("**/*.exs")
|
||||
|> Path.wildcard()
|
||||
|> Enum.sort()
|
||||
|> Enum.reverse()
|
||||
|
||||
if first_tenant do
|
||||
current_tenant_migrations =
|
||||
Ecto.Query.from(row in "schema_migrations",
|
||||
select: row.version
|
||||
)
|
||||
|> repo.all(prefix: first_tenant)
|
||||
|> Enum.map(&to_string/1)
|
||||
if !Enum.empty?(tenant_files) do
|
||||
first_tenant = repo.all_tenants() |> Enum.at(0)
|
||||
|
||||
tenant_files =
|
||||
tenant_migrations_path
|
||||
|> Path.join("**/*.exs")
|
||||
|> Path.wildcard()
|
||||
|> Enum.sort()
|
||||
|> Enum.reverse()
|
||||
|> Enum.filter(fn file ->
|
||||
Enum.any?(current_tenant_migrations, &String.starts_with?(file, &1))
|
||||
end)
|
||||
|> Enum.take(20)
|
||||
|> Enum.map(&String.trim_leading(&1, tenant_migrations_path))
|
||||
|> Enum.with_index()
|
||||
|> Enum.map(fn {file, index} -> "#{index + 1}: #{file}" end)
|
||||
if first_tenant do
|
||||
current_tenant_migrations =
|
||||
Ecto.Query.from(row in "schema_migrations",
|
||||
select: row.version
|
||||
)
|
||||
|> repo.all(prefix: first_tenant)
|
||||
|> Enum.map(&to_string/1)
|
||||
|
||||
tenant_files =
|
||||
tenant_files
|
||||
|> Enum.filter(fn file ->
|
||||
Enum.any?(
|
||||
current_tenant_migrations,
|
||||
&String.starts_with?(Path.basename(file), &1)
|
||||
)
|
||||
end)
|
||||
|> Enum.take(20)
|
||||
|> Enum.map(&String.trim_leading(&1, tenant_migrations_path))
|
||||
|> Enum.with_index()
|
||||
|> Enum.map(fn {file, index} -> "#{index + 1}: #{file}" end)
|
||||
|
||||
if !Enum.empty?(tenant_files) do
|
||||
n =
|
||||
Mix.shell().prompt(
|
||||
"""
|
||||
|
@ -565,13 +571,7 @@ defmodule AshPostgres.DataLayer do
|
|||
|
||||
[]
|
||||
|> AshPostgres.Mix.Helpers.repos!(args)
|
||||
|> Enum.all?(fn repo ->
|
||||
[]
|
||||
|> AshPostgres.Mix.Helpers.tenant_migrations_path(repo)
|
||||
|> Path.join("**/*.exs")
|
||||
|> Path.wildcard()
|
||||
|> Enum.empty?()
|
||||
end)
|
||||
|> Enum.all?(&(not has_tenant_migrations?(&1)))
|
||||
|> case do
|
||||
true ->
|
||||
:ok
|
||||
|
@ -586,6 +586,14 @@ defmodule AshPostgres.DataLayer do
|
|||
Mix.Task.run("ash_postgres.drop", args)
|
||||
end
|
||||
|
||||
defp has_tenant_migrations?(repo) do
|
||||
[]
|
||||
|> AshPostgres.Mix.Helpers.tenant_migrations_path(repo)
|
||||
|> Path.join("**/*.exs")
|
||||
|> Path.wildcard()
|
||||
|> Enum.empty?()
|
||||
end
|
||||
|
||||
import Ecto.Query, only: [from: 2, subquery: 1]
|
||||
|
||||
@impl true
|
||||
|
|
Loading…
Reference in a new issue