diff options
author | Mark Felder <feld@FreeBSD.org> | 2020-10-13 09:54:29 -0500 |
---|---|---|
committer | Mark Felder <feld@FreeBSD.org> | 2020-10-13 09:54:29 -0500 |
commit | 409f694e4f90d34285b43c7e7afc594bc386d893 (patch) | |
tree | 70d3283bcc7e565ba37b253c7cd7dbb94b9d9aa3 /lib/mix/tasks/pleroma/ecto.ex | |
parent | 9968b7efedc64d0239db5578de7fc66ff4ce894d (diff) | |
parent | 8b6221d4ecd1d7e354e7de831dd46e285cb85077 (diff) | |
download | pleroma-409f694e4f90d34285b43c7e7afc594bc386d893.tar.gz |
Merge branch 'develop' into refactor/locked_user_field
Diffstat (limited to 'lib/mix/tasks/pleroma/ecto.ex')
-rw-r--r-- | lib/mix/tasks/pleroma/ecto.ex | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/mix/tasks/pleroma/ecto.ex b/lib/mix/tasks/pleroma/ecto.ex new file mode 100644 index 000000000..3363cd45f --- /dev/null +++ b/lib/mix/tasks/pleroma/ecto.ex @@ -0,0 +1,50 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-onl + +defmodule Mix.Tasks.Pleroma.Ecto do + @doc """ + Ensures the given repository's migrations path exists on the file system. + """ + @spec ensure_migrations_path(Ecto.Repo.t(), Keyword.t()) :: String.t() + def ensure_migrations_path(repo, opts) do + path = opts[:migrations_path] || Path.join(source_repo_priv(repo), "migrations") + + path = + case Path.type(path) do + :relative -> + Path.join(Application.app_dir(:pleroma), path) + + :absolute -> + path + end + + if not File.dir?(path) do + raise_missing_migrations(Path.relative_to_cwd(path), repo) + end + + path + end + + @doc """ + Returns the private repository path relative to the source. + """ + def source_repo_priv(repo) do + config = repo.config() + priv = config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}" + Path.join(Application.app_dir(:pleroma), priv) + end + + defp raise_missing_migrations(path, repo) do + raise(""" + Could not find migrations directory #{inspect(path)} + for repo #{inspect(repo)}. + This may be because you are in a new project and the + migration directory has not been created yet. Creating an + empty directory at the path above will fix this error. + If you expected existing migrations to be found, please + make sure your repository has been properly configured + and the configured path exists. + """) + end +end |