summaryrefslogtreecommitdiff
path: root/priv/repo/migrations/20201005123100_simple_policy_string_to_tuple.exs
diff options
context:
space:
mode:
authorAlex Gleason <alex@alexgleason.me>2021-12-15 19:05:36 -0500
committerAlex Gleason <alex@alexgleason.me>2021-12-15 19:05:36 -0500
commite1b89fe3aa2c03576a6f2418c1e83c0ed64707a3 (patch)
tree6a8b31ef3612c4f8f5b405361c7cb875f4661d84 /priv/repo/migrations/20201005123100_simple_policy_string_to_tuple.exs
parent29d80b39f287ed2488a612280d41e9dd2e40a7cc (diff)
parent6eb7d69e60a96e577de92de232ed48e509f23cd4 (diff)
downloadpleroma-e1b89fe3aa2c03576a6f2418c1e83c0ed64707a3.tar.gz
pleroma-e1b89fe3aa2c03576a6f2418c1e83c0ed64707a3.zip
Merge remote-tracking branch 'origin/develop' into live-dashboard
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