Migrate in-db config after updating to Oban 2.0
authorrinpatch <rinpatch@sdf.org>
Tue, 14 Jul 2020 09:00:53 +0000 (12:00 +0300)
committerrinpatch <rinpatch@sdf.org>
Tue, 14 Jul 2020 10:15:46 +0000 (13:15 +0300)
docs/configuration/cheatsheet.md
priv/repo/migrations/20200714081657_oban_2_0_config_changes.exs [new file with mode: 0644]

index f796330f1080b10ee80fbaa3c9a9684ab5477ee5..7b1fd92f337c16cc16d5db1fd09b61b73cfc54d6 100644 (file)
@@ -629,8 +629,7 @@ Email notifications settings.
 Configuration options described in [Oban readme](https://github.com/sorentwo/oban#usage):
 
 * `repo` - app's Ecto repo (`Pleroma.Repo`)
-* `verbose` - logs verbosity
-* `prune` - non-retryable jobs [pruning settings](https://github.com/sorentwo/oban#pruning) (`:disabled` / `{:maxlen, value}` / `{:maxage, value}`)
+* `log` - logs verbosity
 * `queues` - job queues (see below)
 * `crontab` - periodic jobs, see [`Oban.Cron`](#obancron)
 
diff --git a/priv/repo/migrations/20200714081657_oban_2_0_config_changes.exs b/priv/repo/migrations/20200714081657_oban_2_0_config_changes.exs
new file mode 100644 (file)
index 0000000..c54bb25
--- /dev/null
@@ -0,0 +1,27 @@
+defmodule Elixir.Pleroma.Repo.Migrations.Oban20ConfigChanges do
+  use Ecto.Migration
+  import Ecto.Query
+  alias Pleroma.ConfigDB
+  alias Pleroma.Repo
+
+  def change do
+    config_entry =
+      from(c in ConfigDB, where: c.group == ^":pleroma" and c.key == ^"Oban")
+      |> select([c], struct(c, [:value, :id]))
+      |> Repo.one()
+
+    if config_entry do
+      %{value: value} = config_entry
+
+      value =
+        case Keyword.fetch(value, :verbose) do
+          {:ok, log} -> Keyword.put_new(value, :log, log)
+          _ -> value
+        end
+        |> Keyword.drop([:verbose, :prune])
+
+      Ecto.Changeset.change(config_entry, %{value: value})
+      |> Repo.update()
+    end
+  end
+end