Just a note that since Tagging support is now part of discourse, the way to create a badge for a post with a given tag has changed.
The code now should look like this:
SELECT p.user_id, min(p.created_at) granted_at, MIN(p.id) post_id
FROM badge_posts p
JOIN topics t ON t.id = p.topic_id
JOIN topic_tags tt on t.id = tt.topic_id
JOIN tags on tags.id = tt.tag_id
WHERE category_id = (
SELECT id FROM categories WHERE name ilike 'CATEGORY-NAME'
) AND p.post_number = 1
AND tags.name LIKE 'TAG-NAME'
and (:backfill OR ( p.id IN (:post_ids) ))
GROUP BY p.user_id
Changing all of your Badge Queries is left as an exercise to the admin.
(But I’ve got dozens of badges to change, so I’ll probably have a script that will fix at least mine Real Soon Now. If you’re interested, let me know and I’ll endeavor to make it useful for others.)