From ebee9f59d84c31b755611033d4abe2938201a65e Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 22 Jun 2019 04:17:04 +0300 Subject: [PATCH 1/2] Ecto tasks: Resolve relative path using the application directory instead of cwd and load the application before doing anything In OTP releases cwd != app directory and the configuration is read only if the application is loaded --- lib/mix/pleroma.ex | 4 ++++ lib/mix/tasks/pleroma/ecto/ecto.ex | 11 ++++++++++- lib/mix/tasks/pleroma/ecto/migrate.ex | 2 ++ lib/mix/tasks/pleroma/ecto/rollback.ex | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex index 548c8a0a4..1b758ea33 100644 --- a/lib/mix/pleroma.ex +++ b/lib/mix/pleroma.ex @@ -9,6 +9,10 @@ def start_pleroma do {:ok, _} = Application.ensure_all_started(:pleroma) end + def load_pleroma do + Application.load(:pleroma) + end + def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do Keyword.get(options, opt) || shell_prompt(prompt, defval, defname) end diff --git a/lib/mix/tasks/pleroma/ecto/ecto.ex b/lib/mix/tasks/pleroma/ecto/ecto.ex index af09cb289..324f57fdd 100644 --- a/lib/mix/tasks/pleroma/ecto/ecto.ex +++ b/lib/mix/tasks/pleroma/ecto/ecto.ex @@ -9,6 +9,15 @@ defmodule Mix.Tasks.Pleroma.Ecto do 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 @@ -22,7 +31,7 @@ def ensure_migrations_path(repo, opts) do def source_repo_priv(repo) do config = repo.config() priv = config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}" - Path.join(File.cwd!(), priv) + Path.join(Application.app_dir(:pleroma), priv) end defp raise_missing_migrations(path, repo) do diff --git a/lib/mix/tasks/pleroma/ecto/migrate.ex b/lib/mix/tasks/pleroma/ecto/migrate.ex index 22eafe76f..855c977f6 100644 --- a/lib/mix/tasks/pleroma/ecto/migrate.ex +++ b/lib/mix/tasks/pleroma/ecto/migrate.ex @@ -4,6 +4,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.Migrate do use Mix.Task + import Mix.Pleroma require Logger @shortdoc "Wrapper on `ecto.migrate` task." @@ -37,6 +38,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.Migrate do @impl true def run(args \\ []) do + load_pleroma() {opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases) opts = diff --git a/lib/mix/tasks/pleroma/ecto/rollback.ex b/lib/mix/tasks/pleroma/ecto/rollback.ex index 0033ceba4..2ffb0901c 100644 --- a/lib/mix/tasks/pleroma/ecto/rollback.ex +++ b/lib/mix/tasks/pleroma/ecto/rollback.ex @@ -4,6 +4,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.Rollback do use Mix.Task + import Mix.Pleroma require Logger @shortdoc "Wrapper on `ecto.rollback` task" @@ -36,6 +37,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.Rollback do @impl true def run(args \\ []) do + load_pleroma() {opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases) opts = From 19f16e829d2f5f800483aeb1f48aefca2504d1e6 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 22 Jun 2019 04:33:46 +0300 Subject: [PATCH 2/2] Load the application before executing the create task --- lib/pleroma/release_tasks.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/pleroma/release_tasks.ex b/lib/pleroma/release_tasks.ex index d6720cd05..8afabf463 100644 --- a/lib/pleroma/release_tasks.ex +++ b/lib/pleroma/release_tasks.ex @@ -44,6 +44,8 @@ def rollback(args) do end def create do + Application.load(:pleroma) + case @repo.__adapter__.storage_up(@repo.config) do :ok -> IO.puts("The database for #{inspect(@repo)} has been created")