Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
8a1e0c9b
Commit
8a1e0c9b
authored
Mar 03, 2019
by
Eugenij
Browse files
Added migration to update existing user note counters
parent
c46950d3
Changes
1
Hide whitespace changes
Inline
Side-by-side
priv/repo/migrations/20190303120636_update_user_note_counters.exs
0 → 100644
View file @
8a1e0c9b
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment