Merge branch 'oauth_secure_redirect' into 'develop'
[akkoma] / lib / mix / tasks / pleroma / ecto / ecto.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-onl
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
12 if not File.dir?(path) do
13 raise_missing_migrations(Path.relative_to_cwd(path), repo)
14 end
15
16 path
17 end
18
19 @doc """
20 Returns the private repository path relative to the source.
21 """
22 def source_repo_priv(repo) do
23 config = repo.config()
24 priv = config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
25 Path.join(File.cwd!(), priv)
26 end
27
28 defp raise_missing_migrations(path, repo) do
29 raise("""
30 Could not find migrations directory #{inspect(path)}
31 for repo #{inspect(repo)}.
32 This may be because you are in a new project and the
33 migration directory has not been created yet. Creating an
34 empty directory at the path above will fix this error.
35 If you expected existing migrations to be found, please
36 make sure your repository has been properly configured
37 and the configured path exists.
38 """)
39 end
40 end