summaryrefslogtreecommitdiff
path: root/priv
diff options
context:
space:
mode:
authorMark Felder <feld@FreeBSD.org>2020-06-17 12:50:06 -0500
committerMark Felder <feld@FreeBSD.org>2020-06-17 12:50:06 -0500
commit3462d4b995a995ad523139a865b34a824e02674d (patch)
tree273a000ee55c9bb6a5344a507025600508227382 /priv
parent96493da7bdab4ff4a51cbebf18df4127ddc47990 (diff)
parentd772361e6209e6b5733e9fe52b3671cd222060b3 (diff)
downloadpleroma-3462d4b995a995ad523139a865b34a824e02674d.tar.gz
pleroma-3462d4b995a995ad523139a865b34a824e02674d.zip
Merge branch 'develop' into issue/1855
Diffstat (limited to 'priv')
-rw-r--r--priv/repo/migrations/20200322174133_user_raw_bio.exs9
-rw-r--r--priv/repo/migrations/20200328193433_populate_user_raw_bio.exs25
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