Merge branch 'fix/ecto-tasks-release' into 'develop'

Ecto tasks: Resolve relative path using the application directory instead of cwd and load the application before doing anything

See merge request pleroma/pleroma!1322
This commit is contained in:
rinpatch 2019-06-22 09:19:10 +00:00
commit 53c73cd1a3
5 changed files with 20 additions and 1 deletions

View file

@ -9,6 +9,10 @@ defmodule Mix.Pleroma do
{:ok, _} = Application.ensure_all_started(:pleroma) {:ok, _} = Application.ensure_all_started(:pleroma)
end end
def load_pleroma do
Application.load(:pleroma)
end
def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
Keyword.get(options, opt) || shell_prompt(prompt, defval, defname) Keyword.get(options, opt) || shell_prompt(prompt, defval, defname)
end end

View file

@ -9,6 +9,15 @@ defmodule Mix.Tasks.Pleroma.Ecto do
def ensure_migrations_path(repo, opts) do def ensure_migrations_path(repo, opts) do
path = opts[:migrations_path] || Path.join(source_repo_priv(repo), "migrations") 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 if not File.dir?(path) do
raise_missing_migrations(Path.relative_to_cwd(path), repo) raise_missing_migrations(Path.relative_to_cwd(path), repo)
end end
@ -22,7 +31,7 @@ defmodule Mix.Tasks.Pleroma.Ecto do
def source_repo_priv(repo) do def source_repo_priv(repo) do
config = repo.config() config = repo.config()
priv = config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}" priv = config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
Path.join(File.cwd!(), priv) Path.join(Application.app_dir(:pleroma), priv)
end end
defp raise_missing_migrations(path, repo) do defp raise_missing_migrations(path, repo) do

View file

@ -4,6 +4,7 @@
defmodule Mix.Tasks.Pleroma.Ecto.Migrate do defmodule Mix.Tasks.Pleroma.Ecto.Migrate do
use Mix.Task use Mix.Task
import Mix.Pleroma
require Logger require Logger
@shortdoc "Wrapper on `ecto.migrate` task." @shortdoc "Wrapper on `ecto.migrate` task."
@ -37,6 +38,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.Migrate do
@impl true @impl true
def run(args \\ []) do def run(args \\ []) do
load_pleroma()
{opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases) {opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
opts = opts =

View file

@ -4,6 +4,7 @@
defmodule Mix.Tasks.Pleroma.Ecto.Rollback do defmodule Mix.Tasks.Pleroma.Ecto.Rollback do
use Mix.Task use Mix.Task
import Mix.Pleroma
require Logger require Logger
@shortdoc "Wrapper on `ecto.rollback` task" @shortdoc "Wrapper on `ecto.rollback` task"
@ -36,6 +37,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.Rollback do
@impl true @impl true
def run(args \\ []) do def run(args \\ []) do
load_pleroma()
{opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases) {opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
opts = opts =

View file

@ -44,6 +44,8 @@ defmodule Pleroma.ReleaseTasks do
end end
def create do def create do
Application.load(:pleroma)
case @repo.__adapter__.storage_up(@repo.config) do case @repo.__adapter__.storage_up(@repo.config) do
:ok -> :ok ->
IO.puts("The database for #{inspect(@repo)} has been created") IO.puts("The database for #{inspect(@repo)} has been created")