Fix: Don't start mobilizon server when running migrations

Closes #1126 #1166 #743

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-10-13 11:59:20 +02:00
parent 199add5743
commit 5bce26980a
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
1 changed files with 12 additions and 2 deletions

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