OTP release install guide sceleton
[akkoma] / lib / pleroma / release_tasks.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.ReleaseTasks do
6 @repo Pleroma.Repo
7
8 def run(args) do
9 [task | args] = String.split(args)
10
11 case task do
12 "migrate" -> migrate(args)
13 "create" -> create()
14 "rollback" -> rollback(args)
15 task -> mix_task(task, args)
16 end
17 end
18
19 defp mix_task(task, args) do
20 {:ok, modules} = :application.get_key(:pleroma, :modules)
21
22 module =
23 Enum.find(modules, fn module ->
24 module = Module.split(module)
25
26 match?(["Mix", "Tasks", "Pleroma" | _], module) and
27 String.downcase(List.last(module)) == task
28 end)
29
30 if module do
31 module.run(args)
32 else
33 IO.puts("The task #{task} does not exist")
34 end
35 end
36
37 def migrate(args) do
38 Mix.Tasks.Pleroma.Ecto.Migrate.run(args)
39 end
40
41 def rollback(args) do
42 Mix.Tasks.Pleroma.Ecto.Rollback.run(args)
43 end
44
45 def create do
46 case @repo.__adapter__.storage_up(@repo.config) do
47 :ok ->
48 IO.puts("The database for #{inspect(@repo)} has been created")
49
50 {:error, :already_up} ->
51 IO.puts("The database for #{inspect(@repo)} has already been created")
52
53 {:error, term} when is_binary(term) ->
54 IO.puts(:stderr, "The database for #{inspect(@repo)} couldn't be created: #{term}")
55
56 {:error, term} ->
57 IO.puts(
58 :stderr,
59 "The database for #{inspect(@repo)} couldn't be created: #{inspect(term)}"
60 )
61 end
62 end
63 end