migrations for renaming gun timeout options
authorAlexander Strizhakov <alex.strizhakov@gmail.com>
Sat, 5 Sep 2020 09:41:01 +0000 (12:41 +0300)
committerAlexander Strizhakov <alex.strizhakov@gmail.com>
Mon, 7 Sep 2020 16:59:17 +0000 (19:59 +0300)
priv/repo/migrations/20200905082737_rename_await_up_timeout_in_connections_pool.exs [new file with mode: 0644]
priv/repo/migrations/20200905091427_rename_timeout_in_pools.exs [new file with mode: 0644]

diff --git a/priv/repo/migrations/20200905082737_rename_await_up_timeout_in_connections_pool.exs b/priv/repo/migrations/20200905082737_rename_await_up_timeout_in_connections_pool.exs
new file mode 100644 (file)
index 0000000..22c4066
--- /dev/null
@@ -0,0 +1,13 @@
+defmodule Pleroma.Repo.Migrations.RenameAwaitUpTimeoutInConnectionsPool do
+  use Ecto.Migration
+
+  def change do
+    with %Pleroma.ConfigDB{} = config <-
+           Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: :connections_pool}),
+         {timeout, value} when is_integer(timeout) <- Keyword.pop(config.value, :await_up_timeout) do
+      config
+      |> Ecto.Changeset.change(value: Keyword.put(value, :connect_timeout, timeout))
+      |> Pleroma.Repo.update()
+    end
+  end
+end
diff --git a/priv/repo/migrations/20200905091427_rename_timeout_in_pools.exs b/priv/repo/migrations/20200905091427_rename_timeout_in_pools.exs
new file mode 100644 (file)
index 0000000..bb2f50e
--- /dev/null
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.RenameTimeoutInPools do
+  use Ecto.Migration
+
+  def change do
+    with %Pleroma.ConfigDB{} = config <-
+           Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: :pools}) do
+      updated_value =
+        Enum.map(config.value, fn {pool, pool_value} ->
+          with {timeout, value} when is_integer(timeout) <- Keyword.pop(pool_value, :timeout) do
+            {pool, Keyword.put(value, :recv_timeout, timeout)}
+          end
+        end)
+
+      config
+      |> Ecto.Changeset.change(value: updated_value)
+      |> Pleroma.Repo.update()
+    end
+  end
+end