logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

ecto.ex (1573B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Mix.Tasks.Pleroma.Ecto do
  5. @doc """
  6. Ensures the given repository's migrations path exists on the file system.
  7. """
  8. @spec ensure_migrations_path(Ecto.Repo.t(), Keyword.t()) :: String.t()
  9. def ensure_migrations_path(repo, opts) do
  10. path = opts[:migrations_path] || Path.join(source_repo_priv(repo), "migrations")
  11. path =
  12. case Path.type(path) do
  13. :relative ->
  14. Path.join(Application.app_dir(:pleroma), path)
  15. :absolute ->
  16. path
  17. end
  18. if not File.dir?(path) do
  19. raise_missing_migrations(Path.relative_to_cwd(path), repo)
  20. end
  21. path
  22. end
  23. @doc """
  24. Returns the private repository path relative to the source.
  25. """
  26. def source_repo_priv(repo) do
  27. config = repo.config()
  28. priv = config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
  29. Path.join(Application.app_dir(:pleroma), priv)
  30. end
  31. defp raise_missing_migrations(path, repo) do
  32. raise("""
  33. Could not find migrations directory #{inspect(path)}
  34. for repo #{inspect(repo)}.
  35. This may be because you are in a new project and the
  36. migration directory has not been created yet. Creating an
  37. empty directory at the path above will fix this error.
  38. If you expected existing migrations to be found, please
  39. make sure your repository has been properly configured
  40. and the configured path exists.
  41. """)
  42. end
  43. end