2019-06-08 17:40:40 +03:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2019-06-08 17:40:40 +03:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
|
|
defmodule Pleroma.ReleaseTasks do
|
2019-06-09 13:33:44 +03:00
|
|
|
@repo Pleroma.Repo
|
|
|
|
|
|
2026-04-24 15:04:12 +02:00
|
|
|
# TODO: Kept for some backwards compatibility with buggy pleroma_ctl,
|
|
|
|
|
# if a mismatch between pleroma_ctl and Pleroma accidentaly happens.
|
|
|
|
|
# Remove in the future.
|
|
|
|
|
def run(args) when is_binary(args) do
|
2019-06-08 17:40:40 +03:00
|
|
|
[task | args] = String.split(args)
|
|
|
|
|
|
|
|
|
|
case task do
|
2019-06-19 10:33:33 +00:00
|
|
|
"migrate" -> migrate(args)
|
2019-06-09 13:33:44 +03:00
|
|
|
"create" -> create()
|
2019-06-19 10:33:33 +00:00
|
|
|
"rollback" -> rollback(args)
|
2019-06-08 17:40:40 +03:00
|
|
|
task -> mix_task(task, args)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2026-04-24 15:04:12 +02:00
|
|
|
# HACK: Script arguments need to be received as a list, otherwise (quoted) arguments with
|
|
|
|
|
# whitespace will be broken. Previously the broken string form above was used,
|
|
|
|
|
# escaping in the shell does not help.
|
|
|
|
|
def run(args) when is_list(args) do
|
|
|
|
|
[task | args] = args
|
|
|
|
|
|
|
|
|
|
case task do
|
|
|
|
|
"migrate" -> migrate(args)
|
|
|
|
|
"create" -> create()
|
|
|
|
|
"rollback" -> rollback(args)
|
|
|
|
|
task -> mix_task(task, args)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-11-21 16:07:09 +04:00
|
|
|
def find_module(task) do
|
|
|
|
|
module_name =
|
|
|
|
|
task
|
|
|
|
|
|> String.split(".")
|
|
|
|
|
|> Enum.map(&String.capitalize/1)
|
|
|
|
|
|> then(fn x -> [Mix, Tasks, Pleroma] ++ x end)
|
|
|
|
|
|> Module.concat()
|
|
|
|
|
|
|
|
|
|
case Code.ensure_loaded(module_name) do
|
|
|
|
|
{:module, _} -> module_name
|
|
|
|
|
_ -> nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-08 17:40:40 +03:00
|
|
|
defp mix_task(task, args) do
|
2019-06-20 02:20:20 +03:00
|
|
|
Application.load(:pleroma)
|
2019-06-08 17:40:40 +03:00
|
|
|
|
2024-11-21 16:07:09 +04:00
|
|
|
module = find_module(task)
|
2019-06-08 17:40:40 +03:00
|
|
|
|
|
|
|
|
if module do
|
|
|
|
|
module.run(args)
|
|
|
|
|
else
|
|
|
|
|
IO.puts("The task #{task} does not exist")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-19 10:33:33 +00:00
|
|
|
def migrate(args) do
|
|
|
|
|
Mix.Tasks.Pleroma.Ecto.Migrate.run(args)
|
2019-06-09 13:33:44 +03:00
|
|
|
end
|
|
|
|
|
|
2019-06-19 10:33:33 +00:00
|
|
|
def rollback(args) do
|
|
|
|
|
Mix.Tasks.Pleroma.Ecto.Rollback.run(args)
|
2019-06-09 13:33:44 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create do
|
2019-06-22 04:33:46 +03:00
|
|
|
Application.load(:pleroma)
|
|
|
|
|
|
2019-06-09 13:33:44 +03: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}")
|
|
|
|
|
end
|
2019-06-08 17:40:40 +03:00
|
|
|
end
|
|
|
|
|
end
|