summaryrefslogtreecommitdiff
path: root/priv/repo/migrations/20200907084956_remove_cron_clear_oauth_token_worker_from_oban_config.exs
blob: 278bd33312a44dbbf3631f37068e2c915447fdff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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.RemoveCronClearOauthTokenWorkerFromObanConfig do
  use Ecto.Migration

  def change do
    with %Pleroma.ConfigDB{} = config <-
           Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Oban}),
         crontab when is_list(crontab) <- config.value[:crontab],
         index when is_integer(index) <-
           Enum.find_index(crontab, fn {_, worker} ->
             worker == Pleroma.Workers.Cron.ClearOauthTokenWorker
           end) do
      updated_value = Keyword.put(config.value, :crontab, List.delete_at(crontab, index))

      config
      |> Ecto.Changeset.change(value: updated_value)
      |> Pleroma.Repo.update()
    end
  end
end