diff options
author | Ilja <domainepublic@spectraltheorem.be> | 2020-10-05 14:13:11 +0200 |
---|---|---|
committer | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2021-08-06 07:59:53 +0200 |
commit | 1f52246a026a81f216ebf761b2bda5a2035abbbc (patch) | |
tree | b322d1024bbe40fb94545ee804b50b99fcca7190 /priv/repo/migrations/20201005123100_simple_policy_string_to_tuple.exs | |
parent | c0489f9fac78701345c2902fa59bd99381bc27ab (diff) | |
download | pleroma-1f52246a026a81f216ebf761b2bda5a2035abbbc.tar.gz pleroma-1f52246a026a81f216ebf761b2bda5a2035abbbc.zip |
Add database migrations
* SimplePolicy
* quarentine
* transparency_exclusions
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 | 40 |
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 |