summaryrefslogtreecommitdiff
path: root/priv
diff options
context:
space:
mode:
authorAlex Gleason <alex@alexgleason.me>2020-07-16 16:35:03 -0500
committerAlex Gleason <alex@alexgleason.me>2020-07-16 16:35:03 -0500
commit613e096389d6945016e78499505c3ec5786d0ab0 (patch)
tree4fbaa12610dee60c5293cb0b17361cb53f494348 /priv
parent880301985b49dd0e38a748a9c834eec4d550ea1b (diff)
Migrate :auto_linker --> Pleroma.Formatter in ConfigDB
Diffstat (limited to 'priv')
-rw-r--r--priv/repo/migrations/20200716195806_autolinker_to_linkify.exs37
1 files changed, 37 insertions, 0 deletions
diff --git a/priv/repo/migrations/20200716195806_autolinker_to_linkify.exs b/priv/repo/migrations/20200716195806_autolinker_to_linkify.exs
new file mode 100644
index 000000000..9ec4203eb
--- /dev/null
+++ b/priv/repo/migrations/20200716195806_autolinker_to_linkify.exs
@@ -0,0 +1,37 @@
+defmodule Pleroma.Repo.Migrations.AutolinkerToLinkify do
+ use Ecto.Migration
+
+ alias Pleroma.Repo
+ alias Pleroma.ConfigDB
+
+ @autolinker_path %{group: :auto_linker, key: :opts}
+ @linkify_path %{group: :pleroma, key: Pleroma.Formatter}
+
+ @compat_opts [:class, :rel, :new_window, :truncate, :strip_prefix, :extra]
+
+ def change do
+ with {:ok, {old, new}} <- maybe_get_params() do
+ move_config(old, new)
+ end
+ end
+
+ defp move_config(%{} = old, %{} = new) do
+ {:ok, _} = ConfigDB.update_or_create(new)
+ {:ok, _} = ConfigDB.delete(old)
+ :ok
+ end
+
+ defp maybe_get_params() do
+ with %ConfigDB{value: opts} <- ConfigDB.get_by_params(@autolinker_path),
+ %{} = opts <- transform_opts(opts),
+ %{} = linkify_params <- Map.put(@linkify_path, :value, opts) do
+ {:ok, {@autolinker_path, linkify_params}}
+ end
+ end
+
+ defp transform_opts(opts) when is_list(opts) do
+ opts
+ |> Enum.into(%{})
+ |> Map.take(@compat_opts)
+ end
+end