mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 05:23:18 +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.sort()
|
||||||
|> Enum.reverse()
|
|> Enum.reverse()
|
||||||
|> Enum.filter(fn file ->
|
|> 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)
|
end)
|
||||||
|> Enum.take(20)
|
|> Enum.take(20)
|
||||||
|> Enum.map(&String.trim_leading(&1, migrations_path))
|
|> Enum.map(&String.trim_leading(&1, migrations_path))
|
||||||
|
@ -484,7 +484,15 @@ defmodule AshPostgres.DataLayer do
|
||||||
Mix.Task.run("ash_postgres.rollback", args ++ ["-r", inspect(repo), "-n", to_string(n)])
|
Mix.Task.run("ash_postgres.rollback", args ++ ["-r", inspect(repo), "-n", to_string(n)])
|
||||||
Mix.Task.reenable("ash_postgres.rollback")
|
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 !Enum.empty?(tenant_files) do
|
||||||
|
first_tenant = repo.all_tenants() |> Enum.at(0)
|
||||||
|
|
||||||
if first_tenant do
|
if first_tenant do
|
||||||
current_tenant_migrations =
|
current_tenant_migrations =
|
||||||
|
@ -495,20 +503,18 @@ defmodule AshPostgres.DataLayer do
|
||||||
|> Enum.map(&to_string/1)
|
|> Enum.map(&to_string/1)
|
||||||
|
|
||||||
tenant_files =
|
tenant_files =
|
||||||
tenant_migrations_path
|
tenant_files
|
||||||
|> Path.join("**/*.exs")
|
|
||||||
|> Path.wildcard()
|
|
||||||
|> Enum.sort()
|
|
||||||
|> Enum.reverse()
|
|
||||||
|> Enum.filter(fn file ->
|
|> Enum.filter(fn file ->
|
||||||
Enum.any?(current_tenant_migrations, &String.starts_with?(file, &1))
|
Enum.any?(
|
||||||
|
current_tenant_migrations,
|
||||||
|
&String.starts_with?(Path.basename(file), &1)
|
||||||
|
)
|
||||||
end)
|
end)
|
||||||
|> Enum.take(20)
|
|> Enum.take(20)
|
||||||
|> Enum.map(&String.trim_leading(&1, tenant_migrations_path))
|
|> Enum.map(&String.trim_leading(&1, tenant_migrations_path))
|
||||||
|> Enum.with_index()
|
|> Enum.with_index()
|
||||||
|> Enum.map(fn {file, index} -> "#{index + 1}: #{file}" end)
|
|> Enum.map(fn {file, index} -> "#{index + 1}: #{file}" end)
|
||||||
|
|
||||||
if !Enum.empty?(tenant_files) do
|
|
||||||
n =
|
n =
|
||||||
Mix.shell().prompt(
|
Mix.shell().prompt(
|
||||||
"""
|
"""
|
||||||
|
@ -565,13 +571,7 @@ defmodule AshPostgres.DataLayer do
|
||||||
|
|
||||||
[]
|
[]
|
||||||
|> AshPostgres.Mix.Helpers.repos!(args)
|
|> AshPostgres.Mix.Helpers.repos!(args)
|
||||||
|> Enum.all?(fn repo ->
|
|> Enum.all?(&(not has_tenant_migrations?(&1)))
|
||||||
[]
|
|
||||||
|> AshPostgres.Mix.Helpers.tenant_migrations_path(repo)
|
|
||||||
|> Path.join("**/*.exs")
|
|
||||||
|> Path.wildcard()
|
|
||||||
|> Enum.empty?()
|
|
||||||
end)
|
|
||||||
|> case do
|
|> case do
|
||||||
true ->
|
true ->
|
||||||
:ok
|
:ok
|
||||||
|
@ -586,6 +586,14 @@ defmodule AshPostgres.DataLayer do
|
||||||
Mix.Task.run("ash_postgres.drop", args)
|
Mix.Task.run("ash_postgres.drop", args)
|
||||||
end
|
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]
|
import Ecto.Query, only: [from: 2, subquery: 1]
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
Loading…
Reference in a new issue