moving to mrf namespace migration fix

This commit is contained in:
Alexander Strizhakov 2020-06-23 20:18:27 +03:00
parent c7d69e9256
commit cb96c82f70
No known key found for this signature in database
GPG key ID: 022896A53AEF1381

View file

@ -5,13 +5,11 @@ defmodule Pleroma.Repo.Migrations.MrfConfigMoveFromInstanceNamespace do
@old_keys [:rewrite_policy, :mrf_transparency, :mrf_transparency_exclusions] @old_keys [:rewrite_policy, :mrf_transparency, :mrf_transparency_exclusions]
def change do def change do
config = ConfigDB.get_by_params(%{group: ":pleroma", key: ":instance"}) config = ConfigDB.get_by_params(%{group: :pleroma, key: :instance})
if config do if config do
old_instance = ConfigDB.from_binary(config.value)
mrf = mrf =
old_instance config.value
|> Keyword.take(@old_keys) |> Keyword.take(@old_keys)
|> Keyword.new(fn |> Keyword.new(fn
{:rewrite_policy, policies} -> {:policies, policies} {:rewrite_policy, policies} -> {:policies, policies}
@ -21,15 +19,17 @@ def change do
if mrf != [] do if mrf != [] do
{:ok, _} = {:ok, _} =
ConfigDB.create( %ConfigDB{}
%{group: ":pleroma", key: ":mrf", value: ConfigDB.to_binary(mrf)}, |> ConfigDB.changeset(%{group: :pleroma, key: :mrf, value: mrf})
false |> Pleroma.Repo.insert()
)
new_instance = Keyword.drop(old_instance, @old_keys) new_instance = Keyword.drop(config.value, @old_keys)
if new_instance != [] do if new_instance != [] do
{:ok, _} = ConfigDB.update(config, %{value: ConfigDB.to_binary(new_instance)}, false) {:ok, _} =
config
|> ConfigDB.changeset(%{value: new_instance})
|> Pleroma.Repo.update()
else else
{:ok, _} = ConfigDB.delete(config) {:ok, _} = ConfigDB.delete(config)
end end