logo

pleroma

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

20200323122421_mrf_config_move_from_instance_namespace.exs (1309B)


  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.MrfConfigMoveFromInstanceNamespace do
  5. use Ecto.Migration
  6. alias Pleroma.ConfigDB
  7. @old_keys [:rewrite_policy, :mrf_transparency, :mrf_transparency_exclusions]
  8. def change do
  9. config = ConfigDB.get_by_params(%{group: :pleroma, key: :instance})
  10. if config do
  11. mrf =
  12. config.value
  13. |> Keyword.take(@old_keys)
  14. |> Keyword.new(fn
  15. {:rewrite_policy, policies} -> {:policies, policies}
  16. {:mrf_transparency, transparency} -> {:transparency, transparency}
  17. {:mrf_transparency_exclusions, exclusions} -> {:transparency_exclusions, exclusions}
  18. end)
  19. if mrf != [] do
  20. {:ok, _} =
  21. %ConfigDB{}
  22. |> ConfigDB.changeset(%{group: :pleroma, key: :mrf, value: mrf})
  23. |> Pleroma.Repo.insert()
  24. new_instance = Keyword.drop(config.value, @old_keys)
  25. if new_instance != [] do
  26. {:ok, _} =
  27. config
  28. |> ConfigDB.changeset(%{value: new_instance})
  29. |> Pleroma.Repo.update()
  30. else
  31. {:ok, _} = ConfigDB.delete(config)
  32. end
  33. end
  34. end
  35. end
  36. end