First
[anni] / priv / repo / migrations / 20200722185515_fix_malformed_formatter_config.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Repo.Migrations.FixMalformedFormatterConfig do
6   use Ecto.Migration
7   alias Pleroma.ConfigDB
8
9   @config_path %{group: :pleroma, key: Pleroma.Formatter}
10
11   def change do
12     with %ConfigDB{value: %{} = opts} <- ConfigDB.get_by_params(@config_path),
13          fixed_opts <- Map.to_list(opts) do
14       fix_config(fixed_opts)
15     else
16       _ -> :skipped
17     end
18   end
19
20   defp fix_config(fixed_opts) when is_list(fixed_opts) do
21     {:ok, _} =
22       ConfigDB.update_or_create(%{
23         group: :pleroma,
24         key: Pleroma.Formatter,
25         value: fixed_opts
26       })
27
28     :ok
29   end
30 end