diff options
author | rinpatch <rinpatch@sdf.org> | 2020-06-17 10:34:23 +0000 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2020-06-17 10:34:23 +0000 |
commit | 4ec2fb967e0eb0559e39a6d698107f6af4d7a891 (patch) | |
tree | 6e6d3db526b16681c24e148c19c40073d21b7b4c /priv | |
parent | bb68f9d27c81759132dc791c9fabdb54fbb5341d (diff) | |
parent | e1b07402ab077899dd5b9c0023fbe1c48af259e9 (diff) | |
download | pleroma-4ec2fb967e0eb0559e39a6d698107f6af4d7a891.tar.gz pleroma-4ec2fb967e0eb0559e39a6d698107f6af4d7a891.zip |
Merge branch 'features/users-raw_bio' into 'develop'
User: Add raw_bio, storing unformatted bio
See merge request pleroma/pleroma!2326
Diffstat (limited to 'priv')
-rw-r--r-- | priv/repo/migrations/20200322174133_user_raw_bio.exs | 9 | ||||
-rw-r--r-- | priv/repo/migrations/20200328193433_populate_user_raw_bio.exs | 25 |
2 files changed, 34 insertions, 0 deletions
diff --git a/priv/repo/migrations/20200322174133_user_raw_bio.exs b/priv/repo/migrations/20200322174133_user_raw_bio.exs new file mode 100644 index 000000000..ddf9be4f5 --- /dev/null +++ b/priv/repo/migrations/20200322174133_user_raw_bio.exs @@ -0,0 +1,9 @@ +defmodule Pleroma.Repo.Migrations.UserRawBio do + use Ecto.Migration + + def change do + alter table(:users) do + add_if_not_exists(:raw_bio, :text) + end + end +end 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 |