2019-06-08 07:40:40 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 14:44:49 -08:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-06-08 07:40:40 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.ReleaseTasks do
|
2019-06-09 03:33:44 -07:00
|
|
|
@repo Pleroma.Repo
|
|
|
|
|
2019-06-08 07:40:40 -07:00
|
|
|
def run(args) do
|
|
|
|
[task | args] = String.split(args)
|
|
|
|
|
|
|
|
case task do
|
2019-06-19 03:33:33 -07:00
|
|
|
"migrate" -> migrate(args)
|
2019-06-09 03:33:44 -07:00
|
|
|
"create" -> create()
|
2019-06-19 03:33:33 -07:00
|
|
|
"rollback" -> rollback(args)
|
2019-06-08 07:40:40 -07:00
|
|
|
task -> mix_task(task, args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp mix_task(task, args) do
|
2019-06-19 16:20:20 -07:00
|
|
|
Application.load(:pleroma)
|
2019-06-08 07:40:40 -07:00
|
|
|
{:ok, modules} = :application.get_key(:pleroma, :modules)
|
|
|
|
|
|
|
|
module =
|
|
|
|
Enum.find(modules, fn module ->
|
|
|
|
module = Module.split(module)
|
|
|
|
|
|
|
|
match?(["Mix", "Tasks", "Pleroma" | _], module) and
|
|
|
|
String.downcase(List.last(module)) == task
|
|
|
|
end)
|
|
|
|
|
|
|
|
if module do
|
|
|
|
module.run(args)
|
|
|
|
else
|
|
|
|
IO.puts("The task #{task} does not exist")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-19 03:33:33 -07:00
|
|
|
def migrate(args) do
|
|
|
|
Mix.Tasks.Pleroma.Ecto.Migrate.run(args)
|
2019-06-09 03:33:44 -07:00
|
|
|
end
|
|
|
|
|
2019-06-19 03:33:33 -07:00
|
|
|
def rollback(args) do
|
|
|
|
Mix.Tasks.Pleroma.Ecto.Rollback.run(args)
|
2019-06-09 03:33:44 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def create do
|
2019-06-21 18:33:46 -07:00
|
|
|
Application.load(:pleroma)
|
|
|
|
|
2019-06-09 03:33:44 -07:00
|
|
|
case @repo.__adapter__.storage_up(@repo.config) do
|
|
|
|
:ok ->
|
|
|
|
IO.puts("The database for #{inspect(@repo)} has been created")
|
|
|
|
|
|
|
|
{:error, :already_up} ->
|
|
|
|
IO.puts("The database for #{inspect(@repo)} has already been created")
|
|
|
|
|
|
|
|
{:error, term} when is_binary(term) ->
|
|
|
|
IO.puts(:stderr, "The database for #{inspect(@repo)} couldn't be created: #{term}")
|
|
|
|
|
|
|
|
{:error, term} ->
|
|
|
|
IO.puts(
|
|
|
|
:stderr,
|
|
|
|
"The database for #{inspect(@repo)} couldn't be created: #{inspect(term)}"
|
|
|
|
)
|
|
|
|
end
|
2019-06-08 07:40:40 -07:00
|
|
|
end
|
|
|
|
end
|