Badge DB seed doesn’t appear to work properly.
Steps to repro:
- Get Ubuntu Server 18.04 and add Git PPA to APT per linked instructions
- Follow the official install guide to install a copy of Discourse. Ensure that the configured domain is .nip.io where is the IP address of the server that you connect to.
- After installing go through and follow the installer wizard with all defaults (except set the emoji pack to the apple/top one)
- Visit the badges page using a developer (in default install there’s a mini profiler visible) account
Expected behavior: Badges are sorted correctly like the Discourse.org one in screenshot below.
Current behavior: Badges are all over the place (with a few exceptions they appear under other)
Something is wrong with the badge grouping (maybe it shouldn’t be default_badge_grouping_id in db/fixtures/006_badges.rb but badge_grouping_id instead?).
Discourse.org behavior (expected):
My site’s behavior (current):
DB Seed log from server:
Expand for log
== Seed from /var/www/discourse/db/fixtures/005_badge_types.rb
- BadgeType {:id=>1, :name=>"Gold"}
- BadgeType {:id=>2, :name=>"Silver"}
- BadgeType {:id=>3, :name=>"Bronze"}
== Seed from /var/www/discourse/db/fixtures/006_badges.rb
- BadgeGrouping {:id=>1, :name=>"Getting Started", :default_position=>10}
- BadgeGrouping {:id=>2, :name=>"Community", :default_position=>11}
- BadgeGrouping {:id=>3, :name=>"Posting", :default_position=>12}
- BadgeGrouping {:id=>4, :name=>"Trust Level", :default_position=>13}
- BadgeGrouping {:id=>5, :name=>"Other", :default_position=>14}
- Badge {:id=>1, :name=>"Basic User", :badge_type_id=>3, :query=>"\n SELECT u.id user_id, current_timestamp granted_at FROM users u\n WHERE trust_level >= 1 AND (\n :backfill OR u.id IN (:user_ids)\n )\n ", :default_badge_grouping_id=>4, :trigger=>4, :default_allow_title=>false, :default_icon=>"fa-user", :system=>true}
- Badge {:id=>2, :name=>"Member", :badge_type_id=>3, :query=>"\n SELECT u.id user_id, current_timestamp granted_at FROM users u\n WHERE trust_level >= 2 AND (\n :backfill OR u.id IN (:user_ids)\n )\n ", :default_badge_grouping_id=>4, :trigger=>4, :default_allow_title=>false, :default_icon=>"fa-user", :system=>true}
- Badge {:id=>3, :name=>"Regular", :badge_type_id=>2, :query=>"\n SELECT u.id user_id, current_timestamp granted_at FROM users u\n WHERE trust_level >= 3 AND (\n :backfill OR u.id IN (:user_ids)\n )\n ", :default_badge_grouping_id=>4, :trigger=>4, :default_allow_title=>true, :default_icon=>"fa-user", :system=>true}
- Badge {:id=>4, :name=>"Leader", :badge_type_id=>1, :query=>"\n SELECT u.id user_id, current_timestamp granted_at FROM users u\n WHERE trust_level >= 4 AND (\n :backfill OR u.id IN (:user_ids)\n )\n ", :default_badge_grouping_id=>4, :trigger=>4, :default_allow_title=>true, :default_icon=>"fa-user", :system=>true}
- Badge {:id=>17, :name=>"Reader", :badge_type_id=>3, :multiple_grant=>false, :target_posts=>false, :show_posts=>false, :query=>" SELECT id user_id, current_timestamp granted_at\n FROM users\n WHERE id IN\n (\n SELECT pt.user_id\n FROM post_timings pt\n JOIN badge_posts b ON b.post_number = pt.post_number AND\n b.topic_id = pt.topic_id\n JOIN topics t ON t.id = pt.topic_id\n LEFT JOIN user_badges ub ON ub.badge_id = 17 AND ub.user_id = pt.user_id\n WHERE ub.id IS NULL AND t.posts_count > 100\n GROUP BY pt.user_id, pt.topic_id, t.posts_count\n HAVING count(*) >= t.posts_count\n )\n", :default_badge_grouping_id=>1, :auto_revoke=>false, :system=>true}
- Badge {:id=>16, :name=>"Read Guidelines", :badge_type_id=>3, :multiple_grant=>false, :target_posts=>false, :show_posts=>false, :query=>" SELECT user_id, read_faq granted_at\n FROM user_stats\n WHERE read_faq IS NOT NULL AND (user_id IN (:user_ids) OR :backfill)\n", :default_badge_grouping_id=>1, :trigger=>8, :system=>true}
- Badge {:id=>14, :name=>"First Link", :badge_type_id=>3, :multiple_grant=>false, :target_posts=>true, :show_posts=>true, :query=>" SELECT l.user_id, l.post_id, l.created_at granted_at\n FROM\n (\n SELECT MIN(l1.id) id\n FROM topic_links l1\n JOIN badge_posts p1 ON p1.id = l1.post_id\n JOIN badge_posts p2 ON p2.id = l1.link_post_id\n WHERE NOT reflection AND p1.topic_id <> p2.topic_id AND not quote AND\n (:backfill OR ( p1.id in (:post_ids) ))\n GROUP BY l1.user_id\n ) ids\n JOIN topic_links l ON l.id = ids.id\n", :default_badge_grouping_id=>1, :trigger=>2, :system=>true}
- Badge {:id=>15, :name=>"First Quote", :badge_type_id=>3, :multiple_grant=>false, :target_posts=>true, :show_posts=>true, :query=>" SELECT ids.user_id, q.post_id, q.created_at granted_at\n FROM\n (\n SELECT p1.user_id, MIN(q1.id) id\n FROM quoted_posts q1\n JOIN badge_posts p1 ON p1.id = q1.post_id\n JOIN badge_posts p2 ON p2.id = q1.quoted_post_id\n WHERE (:backfill OR ( p1.id IN (:post_ids) ))\n GROUP BY p1.user_id\n ) ids\n JOIN quoted_posts q ON q.id = ids.id\n", :default_badge_grouping_id=>1, :trigger=>2, :system=>true}
- Badge {:id=>11, :name=>"First Like", :badge_type_id=>3, :multiple_grant=>false, :target_posts=>true, :show_posts=>true, :query=>" SELECT pa1.user_id, pa1.created_at granted_at, pa1.post_id\n FROM (\n SELECT pa.user_id, min(pa.id) id\n FROM post_actions pa\n JOIN badge_posts p on p.id = pa.post_id\n WHERE post_action_type_id = 2 AND\n (:backfill OR pa.post_id IN (:post_ids) )\n GROUP BY pa.user_id\n ) x\n JOIN post_actions pa1 on pa1.id = x.id\n", :default_badge_grouping_id=>1, :trigger=>1, :system=>true}
- Badge {:id=>13, :name=>"First Flag", :badge_type_id=>3, :multiple_grant=>false, :target_posts=>true, :show_posts=>false, :query=>" SELECT pa1.user_id, pa1.created_at granted_at, pa1.post_id\n FROM (\n SELECT pa.user_id, min(pa.id) id\n FROM post_actions pa\n JOIN badge_posts p on p.id = pa.post_id\n WHERE post_action_type_id IN (3,4,8) AND\n (:backfill OR pa.post_id IN (:post_ids) )\n GROUP BY pa.user_id\n ) x\n JOIN post_actions pa1 on pa1.id = x.id\n", :badge_grouping_id=>1, :default_badge_grouping_id=>1, :trigger=>1, :auto_revoke=>false, :system=>true}
- Badge {:id=>25, :name=>"Promoter", :default_icon=>"fa-user-plus", :badge_type_id=>3, :multiple_grant=>false, :target_posts=>false, :show_posts=>false, :query=>"\n SELECT u.id user_id, current_timestamp granted_at\n FROM users u\n WHERE u.id IN (\n SELECT invited_by_id\n FROM invites i\n JOIN users u2 ON u2.id = i.user_id\n WHERE i.deleted_at IS NULL AND u2.active AND u2.trust_level >= 0 AND u2.silenced_till IS NULL\n GROUP BY invited_by_id\n HAVING COUNT(*) >= 1\n ) AND u.active AND u.silenced_till IS NULL AND u.id > 0 AND\n (:backfill OR u.id IN (:user_ids) )\n ", :default_badge_grouping_id=>2, :trigger=>0, :auto_revoke=>true, :system=>true}
- Badge {:id=>26, :name=>"Campaigner", :default_icon=>"fa-user-plus", :badge_type_id=>2, :multiple_grant=>false, :target_posts=>false, :show_posts=>false, :query=>"\n SELECT u.id user_id, current_timestamp granted_at\n FROM users u\n WHERE u.id IN (\n SELECT invited_by_id\n FROM invites i\n JOIN users u2 ON u2.id = i.user_id\n WHERE i.deleted_at IS NULL AND u2.active AND u2.trust_level >= 1 AND u2.silenced_till IS NULL\n GROUP BY invited_by_id\n HAVING COUNT(*) >= 3\n ) AND u.active AND u.silenced_till IS NULL AND u.id > 0 AND\n (:backfill OR u.id IN (:user_ids) )\n ", :default_badge_grouping_id=>2, :trigger=>0, :auto_revoke=>true, :system=>true}
- Badge {:id=>27, :name=>"Champion", :default_icon=>"fa-user-plus", :badge_type_id=>1, :multiple_grant=>false, :target_posts=>false, :show_posts=>false, :query=>"\n SELECT u.id user_id, current_timestamp granted_at\n FROM users u\n WHERE u.id IN (\n SELECT invited_by_id\n FROM invites i\n JOIN users u2 ON u2.id = i.user_id\n WHERE i.deleted_at IS NULL AND u2.active AND u2.trust_level >= 2 AND u2.silenced_till IS NULL\n GROUP BY invited_by_id\n HAVING COUNT(*) >= 5\n ) AND u.active AND u.silenced_till IS NULL AND u.id > 0 AND\n (:backfill OR u.id IN (:user_ids) )\n ", :default_badge_grouping_id=>2, :trigger=>0, :auto_revoke=>true, :system=>true}
- Badge {:id=>12, :name=>"First Share", :badge_type_id=>3, :multiple_grant=>false, :target_posts=>true, :show_posts=>true, :query=>" SELECT views.user_id, i2.post_id, i2.created_at granted_at\n FROM\n (\n SELECT i.user_id, MIN(i.id) i_id\n FROM incoming_links i\n JOIN badge_posts p on p.id = i.post_id\n WHERE i.user_id IS NOT NULL\n GROUP BY i.user_id\n ) as views\n JOIN incoming_links i2 ON i2.id = views.i_id\n", :default_badge_grouping_id=>1, :trigger=>0, :system=>true}
- Badge {:id=>21, :name=>"Nice Share", :badge_type_id=>3, :multiple_grant=>true, :target_posts=>true, :show_posts=>true, :query=>" SELECT views.user_id, i2.post_id, current_timestamp granted_at\n FROM\n (\n SELECT i.user_id, MIN(i.id) i_id\n FROM incoming_links i\n JOIN badge_posts p on p.id = i.post_id\n WHERE i.user_id IS NOT NULL\n GROUP BY i.user_id,i.post_id\n HAVING COUNT(*) > 25\n ) as views\n JOIN incoming_links i2 ON i2.id = views.i_id\n", :default_badge_grouping_id=>2, :trigger=>0, :system=>true}
- Badge {:id=>22, :name=>"Good Share", :badge_type_id=>2, :multiple_grant=>true, :target_posts=>true, :show_posts=>true, :query=>" SELECT views.user_id, i2.post_id, current_timestamp granted_at\n FROM\n (\n SELECT i.user_id, MIN(i.id) i_id\n FROM incoming_links i\n JOIN badge_posts p on p.id = i.post_id\n WHERE i.user_id IS NOT NULL\n GROUP BY i.user_id,i.post_id\n HAVING COUNT(*) > 300\n ) as views\n JOIN incoming_links i2 ON i2.id = views.i_id\n", :default_badge_grouping_id=>2, :trigger=>0, :system=>true}
- Badge {:id=>23, :name=>"Great Share", :badge_type_id=>1, :multiple_grant=>true, :target_posts=>true, :show_posts=>true, :query=>" SELECT views.user_id, i2.post_id, current_timestamp granted_at\n FROM\n (\n SELECT i.user_id, MIN(i.id) i_id\n FROM incoming_links i\n JOIN badge_posts p on p.id = i.post_id\n WHERE i.user_id IS NOT NULL\n GROUP BY i.user_id,i.post_id\n HAVING COUNT(*) > 1000\n ) as views\n JOIN incoming_links i2 ON i2.id = views.i_id\n", :default_badge_grouping_id=>2, :trigger=>0, :system=>true}
- Badge {:id=>5, :name=>"Welcome", :badge_type_id=>3, :multiple_grant=>false, :target_posts=>true, :show_posts=>true, :query=>" SELECT p.user_id, min(post_id) post_id, min(pa.created_at) granted_at\n FROM post_actions pa\n JOIN badge_posts p on p.id = pa.post_id\n WHERE post_action_type_id = 2 AND\n (:backfill OR pa.post_id IN (:post_ids) )\n GROUP BY p.user_id\n", :default_badge_grouping_id=>2, :trigger=>1, :system=>true}
- Badge {:id=>9, :name=>"Autobiographer", :badge_type_id=>3, :multiple_grant=>false, :query=>" SELECT u.id user_id, current_timestamp granted_at\n FROM users u\n JOIN user_profiles up on u.id = up.user_id\n WHERE bio_raw IS NOT NULL AND LENGTH(TRIM(bio_raw)) > 10 AND\n uploaded_avatar_id IS NOT NULL AND\n (:backfill OR u.id IN (:user_ids) )\n", :default_badge_grouping_id=>1, :trigger=>8, :system=>true}
- Badge {:id=>10, :name=>"Editor", :badge_type_id=>3, :multiple_grant=>false, :query=>" SELECT p.user_id, min(p.id) post_id, min(p.created_at) granted_at\n FROM badge_posts p\n WHERE p.self_edits > 0 AND\n (:backfill OR p.id IN (:post_ids) )\n GROUP BY p.user_id\n", :badge_grouping_id=>1, :default_badge_grouping_id=>1, :trigger=>2, :system=>true}
- Badge {:id=>48, :name=>"Wiki Editor", :badge_type_id=>3, :multiple_grant=>false, :target_posts=>true, :query=>"SELECT DISTINCT ON (pr.user_id) pr.user_id, pr.post_id, pr.created_at granted_at\nFROM post_revisions pr\nJOIN badge_posts p on p.id = pr.post_id\nWHERE p.wiki\n AND NOT pr.hidden\n AND (:backfill OR p.id IN (:post_ids))\n", :badge_grouping_id=>1, :default_badge_grouping_id=>1, :trigger=>2, :system=>true}
- Badge {:id=>6, :name=>"Nice Post", :badge_type_id=>3, :multiple_grant=>true, :target_posts=>true, :show_posts=>true, :query=>"\n SELECT p.user_id, p.id post_id, p.updated_at granted_at\n FROM badge_posts p\n WHERE p.post_number > 1 AND p.like_count >= 10 AND\n (:backfill OR p.id IN (:post_ids) )\n ", :default_badge_grouping_id=>3, :trigger=>1, :system=>true}
- Badge {:id=>7, :name=>"Good Post", :badge_type_id=>2, :multiple_grant=>true, :target_posts=>true, :show_posts=>true, :query=>"\n SELECT p.user_id, p.id post_id, p.updated_at granted_at\n FROM badge_posts p\n WHERE p.post_number > 1 AND p.like_count >= 25 AND\n (:backfill OR p.id IN (:post_ids) )\n ", :default_badge_grouping_id=>3, :trigger=>1, :system=>true}
- Badge {:id=>8, :name=>"Great Post", :badge_type_id=>1, :multiple_grant=>true, :target_posts=>true, :show_posts=>true, :query=>"\n SELECT p.user_id, p.id post_id, p.updated_at granted_at\n FROM badge_posts p\n WHERE p.post_number > 1 AND p.like_count >= 50 AND\n (:backfill OR p.id IN (:post_ids) )\n ", :default_badge_grouping_id=>3, :trigger=>1, :system=>true}
- Badge {:id=>18, :name=>"Nice Topic", :badge_type_id=>3, :multiple_grant=>true, :target_posts=>true, :show_posts=>true, :query=>"\n SELECT p.user_id, p.id post_id, p.updated_at granted_at\n FROM badge_posts p\n WHERE p.post_number = 1 AND p.like_count >= 10 AND\n (:backfill OR p.id IN (:post_ids) )\n ", :default_badge_grouping_id=>3, :trigger=>1, :system=>true}
- Badge {:id=>19, :name=>"Good Topic", :badge_type_id=>2, :multiple_grant=>true, :target_posts=>true, :show_posts=>true, :query=>"\n SELECT p.user_id, p.id post_id, p.updated_at granted_at\n FROM badge_posts p\n WHERE p.post_number = 1 AND p.like_count >= 25 AND\n (:backfill OR p.id IN (:post_ids) )\n ", :default_badge_grouping_id=>3, :trigger=>1, :system=>true}
- Badge {:id=>20, :name=>"Great Topic", :badge_type_id=>1, :multiple_grant=>true, :target_posts=>true, :show_posts=>true, :query=>"\n SELECT p.user_id, p.id post_id, p.updated_at granted_at\n FROM badge_posts p\n WHERE p.post_number = 1 AND p.like_count >= 50 AND\n (:backfill OR p.id IN (:post_ids) )\n ", :default_badge_grouping_id=>3, :trigger=>1, :system=>true}
- Badge {:id=>24, :name=>"Anniversary", :default_icon=>"fa-clock-o", :badge_type_id=>2, :default_badge_grouping_id=>2, :query=>nil, :trigger=>0, :auto_revoke=>false, :system=>true, :multiple_grant=>true}
- Badge {:id=>28, :name=>"Popular Link", :badge_type_id=>3, :multiple_grant=>true, :target_posts=>true, :show_posts=>true, :query=>" SELECT tl.user_id, post_id, current_timestamp granted_at\n FROM topic_links tl\n JOIN badge_posts p ON p.id = post_id\n WHERE NOT tl.internal\n AND tl.clicks >= 50\n GROUP BY tl.user_id, tl.post_id\n", :badge_grouping_id=>3, :default_badge_grouping_id=>3, :trigger=>0, :system=>true}
- Badge {:id=>29, :name=>"Hot Link", :badge_type_id=>2, :multiple_grant=>true, :target_posts=>true, :show_posts=>true, :query=>" SELECT tl.user_id, post_id, current_timestamp granted_at\n FROM topic_links tl\n JOIN badge_posts p ON p.id = post_id\n WHERE NOT tl.internal\n AND tl.clicks >= 300\n GROUP BY tl.user_id, tl.post_id\n", :badge_grouping_id=>3, :default_badge_grouping_id=>3, :trigger=>0, :system=>true}
- Badge {:id=>30, :name=>"Famous Link", :badge_type_id=>1, :multiple_grant=>true, :target_posts=>true, :show_posts=>true, :query=>" SELECT tl.user_id, post_id, current_timestamp granted_at\n FROM topic_links tl\n JOIN badge_posts p ON p.id = post_id\n WHERE NOT tl.internal\n AND tl.clicks >= 1000\n GROUP BY tl.user_id, tl.post_id\n", :badge_grouping_id=>3, :default_badge_grouping_id=>3, :trigger=>0, :system=>true}
- Badge {:id=>36, :name=>"Appreciated", :default_icon=>"fa-heart", :badge_type_id=>3, :query=>" SELECT p.user_id, current_timestamp AS granted_at\n FROM posts AS p\n WHERE p.like_count >= 1\n AND (:backfill OR p.user_id IN (:user_ids))\n GROUP BY p.user_id\n HAVING count(*) > 20\n", :default_badge_grouping_id=>2, :trigger=>0, :auto_revoke=>false, :system=>true}
- Badge {:id=>37, :name=>"Respected", :default_icon=>"fa-heart", :badge_type_id=>2, :query=>" SELECT p.user_id, current_timestamp AS granted_at\n FROM posts AS p\n WHERE p.like_count >= 2\n AND (:backfill OR p.user_id IN (:user_ids))\n GROUP BY p.user_id\n HAVING count(*) > 100\n", :default_badge_grouping_id=>2, :trigger=>0, :auto_revoke=>false, :system=>true}
- Badge {:id=>31, :name=>"Admired", :default_icon=>"fa-heart", :badge_type_id=>1, :query=>" SELECT p.user_id, current_timestamp AS granted_at\n FROM posts AS p\n WHERE p.like_count >= 5\n AND (:backfill OR p.user_id IN (:user_ids))\n GROUP BY p.user_id\n HAVING count(*) > 300\n", :default_badge_grouping_id=>2, :trigger=>0, :auto_revoke=>false, :system=>true}
- Badge {:id=>38, :name=>"Thank You", :default_icon=>"fa-heart", :badge_type_id=>3, :query=>" SELECT us.user_id, current_timestamp AS granted_at\n FROM user_stats AS us\n INNER JOIN posts AS p ON p.user_id = us.user_id\n WHERE p.like_count > 0\n AND us.likes_given >= 10\n AND (:backfill OR us.user_id IN (:user_ids))\n GROUP BY us.user_id, us.likes_given\n HAVING COUNT(*) > 20\n", :badge_grouping_id=>2, :default_badge_grouping_id=>2, :trigger=>0, :auto_revoke=>false, :system=>true}
- Badge {:id=>32, :name=>"Gives Back", :default_icon=>"fa-heart", :badge_type_id=>2, :query=>" SELECT us.user_id, current_timestamp AS granted_at\n FROM user_stats AS us\n INNER JOIN posts AS p ON p.user_id = us.user_id\n WHERE p.like_count > 0\n AND us.likes_given >= 100\n AND (:backfill OR us.user_id IN (:user_ids))\n GROUP BY us.user_id, us.likes_given\n HAVING COUNT(*) > 100\n", :badge_grouping_id=>2, :default_badge_grouping_id=>2, :trigger=>0, :auto_revoke=>false, :system=>true}
- Badge {:id=>39, :name=>"Empathetic", :default_icon=>"fa-heart", :badge_type_id=>1, :query=>" SELECT us.user_id, current_timestamp AS granted_at\n FROM user_stats AS us\n INNER JOIN posts AS p ON p.user_id = us.user_id\n WHERE p.like_count > 0\n AND us.likes_given >= 1000\n AND (:backfill OR us.user_id IN (:user_ids))\n GROUP BY us.user_id, us.likes_given\n HAVING COUNT(*) > 500\n", :badge_grouping_id=>2, :default_badge_grouping_id=>2, :trigger=>0, :auto_revoke=>false, :system=>true}
- Badge {:id=>33, :name=>"Out of Love", :default_icon=>"fa-heart", :badge_type_id=>3, :query=>" SELECT gdl.user_id, current_timestamp AS granted_at\n FROM given_daily_likes AS gdl\n WHERE gdl.limit_reached\n AND (:backfill OR gdl.user_id IN (:user_ids))\n GROUP BY gdl.user_id\n HAVING COUNT(*) >= 1\n", :badge_grouping_id=>2, :default_badge_grouping_id=>2, :trigger=>0, :auto_revoke=>false, :system=>true}
- Badge {:id=>34, :name=>"Higher Love", :default_icon=>"fa-heart", :badge_type_id=>2, :query=>" SELECT gdl.user_id, current_timestamp AS granted_at\n FROM given_daily_likes AS gdl\n WHERE gdl.limit_reached\n AND (:backfill OR gdl.user_id IN (:user_ids))\n GROUP BY gdl.user_id\n HAVING COUNT(*) >= 5\n", :badge_grouping_id=>2, :default_badge_grouping_id=>2, :trigger=>0, :auto_revoke=>false, :system=>true}
- Badge {:id=>35, :name=>"Crazy in Love", :default_icon=>"fa-heart", :badge_type_id=>1, :query=>" SELECT gdl.user_id, current_timestamp AS granted_at\n FROM given_daily_likes AS gdl\n WHERE gdl.limit_reached\n AND (:backfill OR gdl.user_id IN (:user_ids))\n GROUP BY gdl.user_id\n HAVING COUNT(*) >= 20\n", :badge_grouping_id=>2, :default_badge_grouping_id=>2, :trigger=>0, :auto_revoke=>false, :system=>true}
- Badge {:id=>40, :name=>"First Mention", :badge_type_id=>3, :multiple_grant=>false, :target_posts=>true, :show_posts=>true, :query=>" SELECT acting_user_id AS user_id, min(target_post_id) AS post_id, min(p.created_at) AS granted_at\n FROM user_actions\n JOIN posts p ON p.id = target_post_id\n JOIN topics t ON t.id = topic_id\n JOIN categories c on c.id = category_id\n WHERE action_type = 7\n AND NOT read_restricted\n AND p.deleted_at IS NULL\n AND t.deleted_at IS NULL\n AND t.visible\n AND t.archetype <> 'private_message'\n AND (:backfill OR p.id IN (:post_ids))\n GROUP BY acting_user_id\n", :badge_grouping_id=>1, :default_badge_grouping_id=>1, :trigger=>2, :system=>true}
- Badge {:id=>41, :name=>"First Emoji", :badge_type_id=>3, :multiple_grant=>false, :target_posts=>true, :show_posts=>true, :query=>nil, :badge_grouping_id=>1, :default_badge_grouping_id=>1, :trigger=>0, :system=>true}
- Badge {:id=>42, :name=>"First Onebox", :badge_type_id=>3, :multiple_grant=>false, :target_posts=>true, :show_posts=>true, :query=>nil, :badge_grouping_id=>1, :default_badge_grouping_id=>1, :trigger=>0, :system=>true}
- Badge {:id=>43, :name=>"First Reply By Email", :badge_type_id=>3, :multiple_grant=>false, :target_posts=>true, :show_posts=>true, :query=>nil, :badge_grouping_id=>1, :default_badge_grouping_id=>1, :trigger=>0, :system=>true}
- Badge {:id=>44, :name=>"New User of the Month", :badge_type_id=>3, :multiple_grant=>false, :target_posts=>false, :show_posts=>false, :query=>nil, :badge_grouping_id=>1, :default_badge_grouping_id=>1, :trigger=>0, :system=>true}
- Badge {:id=>45, :name=>"Enthusiast", :default_icon=>"fa-eye", :badge_type_id=>3, :query=>"WITH consecutive_visits AS (\n SELECT user_id\n , visited_at\n , visited_at - (DENSE_RANK() OVER (PARTITION BY user_id ORDER BY visited_at))::int s\n FROM user_visits\n), visits AS (\n SELECT user_id\n , MIN(visited_at) \"start\"\n , DENSE_RANK() OVER (PARTITION BY user_id ORDER BY s) \"rank\"\n FROM consecutive_visits\nGROUP BY user_id, s\n HAVING COUNT(*) >= 10\n)\nSELECT user_id\n , \"start\" + interval '10 days' \"granted_at\"\n FROM visits\n WHERE \"rank\" = 1\n", :badge_grouping_id=>2, :default_badge_grouping_id=>2, :trigger=>0, :auto_revoke=>false, :system=>true}
- Badge {:id=>46, :name=>"Aficionado", :default_icon=>"fa-eye", :badge_type_id=>2, :query=>"WITH consecutive_visits AS (\n SELECT user_id\n , visited_at\n , visited_at - (DENSE_RANK() OVER (PARTITION BY user_id ORDER BY visited_at))::int s\n FROM user_visits\n), visits AS (\n SELECT user_id\n , MIN(visited_at) \"start\"\n , DENSE_RANK() OVER (PARTITION BY user_id ORDER BY s) \"rank\"\n FROM consecutive_visits\nGROUP BY user_id, s\n HAVING COUNT(*) >= 100\n)\nSELECT user_id\n , \"start\" + interval '100 days' \"granted_at\"\n FROM visits\n WHERE \"rank\" = 1\n", :badge_grouping_id=>2, :default_badge_grouping_id=>2, :trigger=>0, :auto_revoke=>false, :system=>true}
- Badge {:id=>47, :name=>"Devotee", :default_icon=>"fa-eye", :badge_type_id=>1, :query=>"WITH consecutive_visits AS (\n SELECT user_id\n , visited_at\n , visited_at - (DENSE_RANK() OVER (PARTITION BY user_id ORDER BY visited_at))::int s\n FROM user_visits\n), visits AS (\n SELECT user_id\n , MIN(visited_at) \"start\"\n , DENSE_RANK() OVER (PARTITION BY user_id ORDER BY s) \"rank\"\n FROM consecutive_visits\nGROUP BY user_id, s\n HAVING COUNT(*) >= 365\n)\nSELECT user_id\n , \"start\" + interval '365 days' \"granted_at\"\n FROM visits\n WHERE \"rank\" = 1\n", :badge_grouping_id=>2, :default_badge_grouping_id=>2, :trigger=>0, :auto_revoke=>false, :system=>true}