Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1KB

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