summaryrefslogtreecommitdiff
path: root/priv/repo/migrations/20201005123100_simple_policy_string_to_tuple.exs
diff options
context:
space:
mode:
authorAlex Gleason <alex@alexgleason.me>2021-11-24 17:58:58 -0600
committerAlex Gleason <alex@alexgleason.me>2021-11-24 17:58:58 -0600
commit720198d56950ca98f4d947dd630b0e170eda569b (patch)
treecd20e64e7daaa8ba033ba6510e137de2d2ccb24e /priv/repo/migrations/20201005123100_simple_policy_string_to_tuple.exs
parentcb9359335f6b0e1d19fb82e4045740d30767254c (diff)
parentc97f99ccf2a51c7f1078d7a20006deae2df3d12c (diff)
downloadpleroma-720198d56950ca98f4d947dd630b0e170eda569b.tar.gz
pleroma-720198d56950ca98f4d947dd630b0e170eda569b.zip
Merge remote-tracking branch 'pleroma/develop' into manifest
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.exs40
1 files changed, 40 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..77a4a7311
--- /dev/null
+++ b/priv/repo/migrations/20201005123100_simple_policy_string_to_tuple.exs
@@ -0,0 +1,40 @@
+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