summaryrefslogtreecommitdiff
path: root/priv/repo/migrations/20200722185515_fix_malformed_formatter_config.exs
blob: 2b0938f03bd6446d796d2b7f592ebae14aeabe18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Repo.Migrations.FixMalformedFormatterConfig do
  use Ecto.Migration
  alias Pleroma.ConfigDB

  @config_path %{group: :pleroma, key: Pleroma.Formatter}

  def change do
    with %ConfigDB{value: %{} = opts} <- ConfigDB.get_by_params(@config_path),
         fixed_opts <- Map.to_list(opts) do
      fix_config(fixed_opts)
    else
      _ -> :skipped
    end
  end

  defp fix_config(fixed_opts) when is_list(fixed_opts) do
    {:ok, _} =
      ConfigDB.update_or_create(%{
        group: :pleroma,
        key: Pleroma.Formatter,
        value: fixed_opts
      })

    :ok
  end
end