logo

pleroma

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

20201005123100_simple_policy_string_to_tuple.exs (1238B)


  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.Repo.Migrations.SimplePolicyStringToTuple do
  5. use Ecto.Migration
  6. alias Pleroma.ConfigDB
  7. def up, do: ConfigDB.get_by_params(%{group: :pleroma, key: :mrf_simple}) |> update_to_tuples
  8. def down, do: ConfigDB.get_by_params(%{group: :pleroma, key: :mrf_simple}) |> update_to_strings
  9. defp update_to_tuples(%{value: value}) do
  10. new_value =
  11. value
  12. |> Enum.map(fn {k, v} ->
  13. {k,
  14. Enum.map(v, fn
  15. {instance, reason} -> {instance, reason}
  16. instance -> {instance, ""}
  17. end)}
  18. end)
  19. ConfigDB.update_or_create(%{group: :pleroma, key: :mrf_simple, value: new_value})
  20. end
  21. defp update_to_tuples(nil), do: {:ok, nil}
  22. defp update_to_strings(%{value: value}) do
  23. new_value =
  24. value
  25. |> Enum.map(fn {k, v} ->
  26. {k,
  27. Enum.map(v, fn
  28. {instance, _} -> instance
  29. instance -> instance
  30. end)}
  31. end)
  32. ConfigDB.update_or_create(%{group: :pleroma, key: :mrf_simple, value: new_value})
  33. end
  34. defp update_to_strings(nil), do: {:ok, nil}
  35. end