Merge branch 'moving-mrf-namespace-migration-fix' into 'develop'

Moving to mrf namespace migration fix

See merge request pleroma/pleroma!2676
This commit is contained in:
feld 2020-06-23 18:51:37 +00:00
commit b4a502fc8b
1 changed files with 10 additions and 10 deletions

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