summaryrefslogtreecommitdiff
path: root/priv/repo/migrations/20200328193433_populate_user_raw_bio.exs
diff options
context:
space:
mode:
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>2020-03-23 22:52:25 +0100
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>2020-06-06 16:23:16 +0200
commite1b07402ab077899dd5b9c0023fbe1c48af259e9 (patch)
treeab438cb25c66419223c7c5501e809983384cf801 /priv/repo/migrations/20200328193433_populate_user_raw_bio.exs
parentd74985af2381b1c0dae2bc9c79c14582e5c61b97 (diff)
downloadpleroma-e1b07402ab077899dd5b9c0023fbe1c48af259e9.tar.gz
pleroma-e1b07402ab077899dd5b9c0023fbe1c48af259e9.zip
User: Add raw_bio, storing unformatted bio
Related: https://git.pleroma.social/pleroma/pleroma/issues/1643
Diffstat (limited to 'priv/repo/migrations/20200328193433_populate_user_raw_bio.exs')
-rw-r--r--priv/repo/migrations/20200328193433_populate_user_raw_bio.exs25
1 files changed, 25 insertions, 0 deletions
diff --git a/priv/repo/migrations/20200328193433_populate_user_raw_bio.exs b/priv/repo/migrations/20200328193433_populate_user_raw_bio.exs
new file mode 100644
index 000000000..cb35db3f5
--- /dev/null
+++ b/priv/repo/migrations/20200328193433_populate_user_raw_bio.exs
@@ -0,0 +1,25 @@
+defmodule Pleroma.Repo.Migrations.PopulateUserRawBio do
+ use Ecto.Migration
+ import Ecto.Query
+ alias Pleroma.User
+ alias Pleroma.Repo
+
+ def change do
+ {:ok, _} = Application.ensure_all_started(:fast_sanitize)
+
+ User.Query.build(%{local: true})
+ |> select([u], struct(u, [:id, :ap_id, :bio]))
+ |> Repo.stream()
+ |> Enum.each(fn %{bio: bio} = user ->
+ if bio do
+ raw_bio =
+ bio
+ |> String.replace(~r(<br */?>), "\n")
+ |> Pleroma.HTML.strip_tags()
+
+ Ecto.Changeset.cast(user, %{raw_bio: raw_bio}, [:raw_bio])
+ |> Repo.update()
+ end
+ end)
+ end
+end