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