diff options
author | eugenijm <eugenijm@protonmail.com> | 2019-03-03 15:35:32 +0300 |
---|---|---|
committer | eugenijm <eugenijm@protonmail.com> | 2019-03-03 15:35:32 +0300 |
commit | 8a1e0c9bee4173a7cd2c6b6174293097d78bea19 (patch) | |
tree | 05fa1d58416fc4f93f8f203f59ec7151e23c48ff | |
parent | c46950d3b16e6fe1ebb86a202ca47a810bfb76dc (diff) | |
download | pleroma-8a1e0c9bee4173a7cd2c6b6174293097d78bea19.tar.gz |
Added migration to update existing user note counters
-rw-r--r-- | priv/repo/migrations/20190303120636_update_user_note_counters.exs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/priv/repo/migrations/20190303120636_update_user_note_counters.exs b/priv/repo/migrations/20190303120636_update_user_note_counters.exs new file mode 100644 index 000000000..54e68f7c9 --- /dev/null +++ b/priv/repo/migrations/20190303120636_update_user_note_counters.exs @@ -0,0 +1,41 @@ +defmodule Pleroma.Repo.Migrations.UpdateUserNoteCounters do + use Ecto.Migration + + @public "https://www.w3.org/ns/activitystreams#Public" + + def up do + execute """ + WITH public_note_count AS ( + SELECT + data->>'actor' AS actor, + count(id) AS count + FROM objects + WHERE data->>'type' = 'Note' AND ( + data->'cc' ? '#{@public}' OR data->'to' ? '#{@public}' + ) + GROUP BY data->>'actor' + ) + UPDATE users AS u + SET "info" = jsonb_set(u.info, '{note_count}', o.count::varchar::jsonb, true) + FROM public_note_count AS o + WHERE u.ap_id = o.actor + """ + end + + def down do + execute """ + WITH public_note_count AS ( + SELECT + data->>'actor' AS actor, + count(id) AS count + FROM objects + WHERE data->>'type' = 'Note' + GROUP BY data->>'actor' + ) + UPDATE users AS u + SET "info" = jsonb_set(u.info, '{note_count}', o.count::varchar::jsonb, true) + FROM public_note_count AS o + WHERE u.ap_id = o.actor + """ + end +end |