diff options
| author | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2022-12-23 17:05:05 +0100 |
|---|---|---|
| committer | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2022-12-23 17:05:05 +0100 |
| commit | 7d68d64d633a8ba43965a6f93d22cb0ae76027e0 (patch) | |
| tree | 6c00d45be1aa1fe63ffff71bc2153cdff34e104f /priv/repo/migrations/20201005123100_simple_policy_string_to_tuple.exs | |
| parent | d8e326467c30b95c5164f6e29512057dce3c2077 (diff) | |
| parent | 6bce88b9e7876d32ea9146a580454053f0ef3790 (diff) | |
| download | pleroma-7d68d64d633a8ba43965a6f93d22cb0ae76027e0.tar.gz pleroma-7d68d64d633a8ba43965a6f93d22cb0ae76027e0.zip | |
Merge back 2.4.5
Diffstat (limited to 'priv/repo/migrations/20201005123100_simple_policy_string_to_tuple.exs')
| -rw-r--r-- | priv/repo/migrations/20201005123100_simple_policy_string_to_tuple.exs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/priv/repo/migrations/20201005123100_simple_policy_string_to_tuple.exs b/priv/repo/migrations/20201005123100_simple_policy_string_to_tuple.exs new file mode 100644 index 000000000..4c6b09da6 --- /dev/null +++ b/priv/repo/migrations/20201005123100_simple_policy_string_to_tuple.exs @@ -0,0 +1,44 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Repo.Migrations.SimplePolicyStringToTuple do + use Ecto.Migration + + alias Pleroma.ConfigDB + + def up, do: ConfigDB.get_by_params(%{group: :pleroma, key: :mrf_simple}) |> update_to_tuples + def down, do: ConfigDB.get_by_params(%{group: :pleroma, key: :mrf_simple}) |> update_to_strings + + defp update_to_tuples(%{value: value}) do + new_value = + value + |> Enum.map(fn {k, v} -> + {k, + Enum.map(v, fn + {instance, reason} -> {instance, reason} + instance -> {instance, ""} + end)} + end) + + ConfigDB.update_or_create(%{group: :pleroma, key: :mrf_simple, value: new_value}) + end + + defp update_to_tuples(nil), do: {:ok, nil} + + defp update_to_strings(%{value: value}) do + new_value = + value + |> Enum.map(fn {k, v} -> + {k, + Enum.map(v, fn + {instance, _} -> instance + instance -> instance + end)} + end) + + ConfigDB.update_or_create(%{group: :pleroma, key: :mrf_simple, value: new_value}) + end + + defp update_to_strings(nil), do: {:ok, nil} +end |
