Allow to use Mix tasks inside Releases
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
committed by
prichier
parent
a269d77044
commit
01f746a5d2
@@ -1,11 +1,53 @@
|
||||
# Portions of this file are derived from Pleroma:
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mobilizon.CLI do
|
||||
@app :mobilizon
|
||||
@moduledoc """
|
||||
CLI wrapper for releases
|
||||
"""
|
||||
alias Mix.Tasks.Mobilizon.Ecto.{Migrate, Rollback}
|
||||
|
||||
def migrate do
|
||||
Application.load(@app)
|
||||
def run(args) do
|
||||
[task | args] = String.split(args)
|
||||
|
||||
for repo <- Application.fetch_env!(@app, :ecto_repos) do
|
||||
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
|
||||
case task do
|
||||
"migrate" -> migrate(args)
|
||||
"rollback" -> rollback(args)
|
||||
task -> mix_task(task, args)
|
||||
end
|
||||
end
|
||||
|
||||
defp mix_task(task, args) do
|
||||
Application.load(:mobilizon)
|
||||
{:ok, modules} = :application.get_key(:mobilizon, :modules)
|
||||
|
||||
module =
|
||||
Enum.find(modules, fn module ->
|
||||
module = Module.split(module)
|
||||
|
||||
case module do
|
||||
["Mix", "Tasks", "Mobilizon" | rest] ->
|
||||
String.downcase(Enum.join(rest, ".")) == task
|
||||
|
||||
_ ->
|
||||
false
|
||||
end
|
||||
end)
|
||||
|
||||
if module do
|
||||
module.run(args)
|
||||
else
|
||||
IO.puts("The task #{task} does not exist")
|
||||
end
|
||||
end
|
||||
|
||||
def migrate(args) do
|
||||
Migrate.run(args)
|
||||
end
|
||||
|
||||
def rollback(args) do
|
||||
Rollback.run(args)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user