Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into update-validator
[akkoma] / priv / repo / migrations / 20200328193433_populate_user_raw_bio.exs
1 defmodule Pleroma.Repo.Migrations.PopulateUserRawBio do
2 use Ecto.Migration
3 import Ecto.Query
4 alias Pleroma.User
5 alias Pleroma.Repo
6
7 def change do
8 {:ok, _} = Application.ensure_all_started(:fast_sanitize)
9
10 User.Query.build(%{local: true})
11 |> select([u], struct(u, [:id, :ap_id, :bio]))
12 |> Repo.stream()
13 |> Enum.each(fn %{bio: bio} = user ->
14 if bio do
15 raw_bio =
16 bio
17 |> String.replace(~r(<br */?>), "\n")
18 |> Pleroma.HTML.strip_tags()
19
20 Ecto.Changeset.cast(user, %{raw_bio: raw_bio}, [:raw_bio])
21 |> Repo.update()
22 end
23 end)
24 end
25 end