move to 2.5.5
[anni] / priv / repo / migrations / 20200906072147_remove_cron_stats_worker_from_oban_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.RemoveCronStatsWorkerFromObanConfig do
6   use Ecto.Migration
7
8   def change do
9     with %Pleroma.ConfigDB{} = config <-
10            Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Oban}),
11          crontab when is_list(crontab) <- config.value[:crontab],
12          index when is_integer(index) <-
13            Enum.find_index(crontab, fn {_, worker} ->
14              worker == Pleroma.Workers.Cron.StatsWorker
15            end) do
16       updated_value = Keyword.put(config.value, :crontab, List.delete_at(crontab, index))
17
18       config
19       |> Ecto.Changeset.change(value: updated_value)
20       |> Pleroma.Repo.update()
21     end
22   end
23 end