logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

release_tasks.ex (1495B)


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