1 defmodule Pleroma.Repo.Migrations.RenameInstanceChat do
6 @instance_params %{group: :pleroma, key: :instance}
7 @shout_params %{group: :pleroma, key: :shout}
8 @chat_params %{group: :pleroma, key: :chat}
11 instance_updated? = maybe_update_instance_key(:up) != :noop
12 chat_updated? = maybe_update_chat_key(:up) != :noop
14 case Enum.any?([instance_updated?, chat_updated?]) do
21 instance_updated? = maybe_update_instance_key(:down) != :noop
22 chat_updated? = maybe_update_chat_key(:down) != :noop
24 case Enum.any?([instance_updated?, chat_updated?]) do
30 # pleroma.instance.chat_limit -> pleroma.shout.limit
31 defp maybe_update_instance_key(:up) do
32 with %ConfigDB{value: values} <- ConfigDB.get_by_params(@instance_params),
33 limit when is_integer(limit) <- values[:chat_limit] do
34 @shout_params |> Map.put(:value, limit: limit) |> ConfigDB.update_or_create()
35 @instance_params |> Map.put(:subkeys, [":chat_limit"]) |> ConfigDB.delete()
42 # pleroma.shout.limit -> pleroma.instance.chat_limit
43 defp maybe_update_instance_key(:down) do
44 with %ConfigDB{value: values} <- ConfigDB.get_by_params(@shout_params),
45 limit when is_integer(limit) <- values[:limit] do
46 @instance_params |> Map.put(:value, chat_limit: limit) |> ConfigDB.update_or_create()
47 @shout_params |> Map.put(:subkeys, [":limit"]) |> ConfigDB.delete()
54 # pleroma.chat.enabled -> pleroma.shout.enabled
55 defp maybe_update_chat_key(:up) do
56 with %ConfigDB{value: values} <- ConfigDB.get_by_params(@chat_params),
57 enabled? when is_boolean(enabled?) <- values[:enabled] do
58 @shout_params |> Map.put(:value, enabled: enabled?) |> ConfigDB.update_or_create()
59 @chat_params |> Map.put(:subkeys, [":enabled"]) |> ConfigDB.delete()
66 # pleroma.shout.enabled -> pleroma.chat.enabled
67 defp maybe_update_chat_key(:down) do
68 with %ConfigDB{value: values} <- ConfigDB.get_by_params(@shout_params),
69 enabled? when is_boolean(enabled?) <- values[:enabled] do
70 @chat_params |> Map.put(:value, enabled: enabled?) |> ConfigDB.update_or_create()
71 @shout_params |> Map.put(:subkeys, [":enabled"]) |> ConfigDB.delete()