From 5bce26980a4709808889cd3df340b1c234a6c1dd Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 13 Oct 2022 11:59:20 +0200 Subject: [PATCH] Fix: Don't start mobilizon server when running migrations Closes #1126 #1166 #743 Signed-off-by: Thomas Citharel --- lib/mix/tasks/mobilizon/ecto/migrate.ex | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/mix/tasks/mobilizon/ecto/migrate.ex b/lib/mix/tasks/mobilizon/ecto/migrate.ex index 3e6c8812e..c53915435 100644 --- a/lib/mix/tasks/mobilizon/ecto/migrate.ex +++ b/lib/mix/tasks/mobilizon/ecto/migrate.ex @@ -26,7 +26,9 @@ defmodule Mix.Tasks.Mobilizon.Ecto.Migrate do migrations_path: :string ] + @app :mobilizon @repo Mobilizon.Storage.Repo + @start_apps [:logger, :ssl, :postgrex, :ecto] @moduledoc """ Changes `Logger` level to `:info` before start migration. @@ -37,12 +39,12 @@ defmodule Mix.Tasks.Mobilizon.Ecto.Migrate do mix mobilizon.ecto.migrate [OPTIONS] Options: - - see https://hexdocs.pm/ecto/2.0.0/Mix.Tasks.Ecto.Migrate.html + - see https://hexdocs.pm/ecto_sql/Mix.Tasks.Ecto.Migrate.html """ @impl true def run(args \\ []) do - start_mobilizon() + load_app() {opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases) if Application.get_env(:mobilizon, @repo)[:ssl] do @@ -68,4 +70,12 @@ defmodule Mix.Tasks.Mobilizon.Ecto.Migrate do Logger.configure(level: level) end + + defp load_app do + IO.puts("Loading app..") + Application.load(@app) + IO.puts("Starting dependencies..") + Enum.each(@start_apps, &Application.ensure_all_started/1) + if mix_task?(), do: Mix.Task.run("app.config") + end end