Merge branch 'fix-migrations-without-starting-mbz' into 'main'

Fix: Don't start mobilizon server when running migrations

Closes #743, #1166 et #1126

See merge request framasoft/mobilizon!1291
This commit is contained in:
Thomas Citharel 2022-10-13 10:40:39 +00:00
commit d8103fb1a5

View file

@ -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