Rename Activity.Search to Search.DatabaseSearch
[akkoma] / lib / pleroma / release_tasks.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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 Application.load(:pleroma)
21 {:ok, modules} = :application.get_key(:pleroma, :modules)
22
23 module =
24 Enum.find(modules, fn module ->
25 module = Module.split(module)
26
27 match?(["Mix", "Tasks", "Pleroma" | _], module) and
28 String.downcase(List.last(module)) == task
29 end)
30
31 if module do
32 module.run(args)
33 else
34 IO.puts("The task #{task} does not exist")
35 end
36 end
37
38 def migrate(args) do
39 Mix.Tasks.Pleroma.Ecto.Migrate.run(args)
40 end
41
42 def rollback(args) do
43 Mix.Tasks.Pleroma.Ecto.Rollback.run(args)
44 end
45
46 def create do
47 Application.load(:pleroma)
48
49 case @repo.__adapter__.storage_up(@repo.config) do
50 :ok ->
51 IO.puts("The database for #{inspect(@repo)} has been created")
52
53 {:error, :already_up} ->
54 IO.puts("The database for #{inspect(@repo)} has already been created")
55
56 {:error, term} when is_binary(term) ->
57 IO.puts(:stderr, "The database for #{inspect(@repo)} couldn't be created: #{term}")
58
59 {:error, term} ->
60 IO.puts(
61 :stderr,
62 "The database for #{inspect(@repo)} couldn't be created: #{inspect(term)}"
63 )
64 end
65 end
66 end