discourse/db/fixtures/006_badges.rb

220 lines
5.8 KiB
Ruby
Raw Normal View History

2014-07-17 02:10:44 -04:00
BadgeGrouping.seed do |g|
g.id = BadgeGrouping::GettingStarted
2014-07-17 02:10:44 -04:00
g.name = "Getting Started"
g.default_position = 10
2014-07-17 02:10:44 -04:00
end
BadgeGrouping.seed do |g|
g.id = BadgeGrouping::Community
2014-07-17 02:10:44 -04:00
g.name = "Community"
g.default_position = 11
2014-07-17 02:10:44 -04:00
end
BadgeGrouping.seed do |g|
g.id = BadgeGrouping::Posting
2014-07-17 02:10:44 -04:00
g.name = "Posting"
g.default_position = 12
2014-07-17 02:10:44 -04:00
end
BadgeGrouping.seed do |g|
g.id = BadgeGrouping::TrustLevel
2014-07-17 02:10:44 -04:00
g.name = "Trust Level"
g.default_position = 13
2014-07-17 02:10:44 -04:00
end
BadgeGrouping.seed do |g|
g.id = BadgeGrouping::Other
2014-07-17 02:10:44 -04:00
g.name = "Other"
g.default_position = 14
2014-07-17 02:10:44 -04:00
end
# BUGFIX
2014-07-26 21:30:55 -04:00
Badge.exec_sql "UPDATE badges
2014-07-18 01:55:42 -04:00
SET badge_grouping_id = -1
WHERE NOT EXISTS (
SELECT 1 FROM badge_groupings g
WHERE g.id = badge_grouping_id
2014-07-26 21:30:55 -04:00
) OR (id < 100 AND badge_grouping_id = #{BadgeGrouping::Other} )"
2014-06-17 02:29:49 -04:00
# Trust level system badges.
trust_level_badges = [
2014-07-07 03:55:25 -04:00
{id: 1, name: "Basic User", type: BadgeType::Bronze},
{id: 2, name: "Regular User", type: BadgeType::Bronze},
{id: 3, name: "Leader", type: BadgeType::Silver},
{id: 4, name: "Elder", type: BadgeType::Gold}
]
trust_level_badges.each do |spec|
Badge.seed do |b|
b.id = spec[:id]
b.default_name = spec[:name]
b.badge_type_id = spec[:type]
b.query = Badge::Queries.trust_level(spec[:id])
b.default_badge_grouping_id = BadgeGrouping::TrustLevel
2014-07-21 22:46:31 -04:00
b.trigger = Badge::Trigger::TrustLevelChange
# allow title for leader and elder
2014-07-29 18:46:46 -04:00
b.default_allow_title = spec[:id] > 2
b.system = true
end
end
Badge.seed do |b|
b.id = Badge::Reader
b.default_name = "Reader"
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = false
b.show_posts = false
b.query = Badge::Queries::Reader
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
b.auto_revoke = false
b.system = true
end
2014-07-11 03:32:29 -04:00
Badge.seed do |b|
2014-07-16 02:26:22 -04:00
b.id = Badge::ReadGuidelines
b.default_name = "Read Guidelines"
2014-07-11 03:32:29 -04:00
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = false
b.show_posts = false
2014-07-16 02:26:22 -04:00
b.query = Badge::Queries::ReadGuidelines
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
b.trigger = Badge::Trigger::UserChange
b.system = true
2014-07-11 03:32:29 -04:00
end
2014-07-09 21:18:02 -04:00
Badge.seed do |b|
b.id = Badge::FirstLink
b.default_name = "First Link"
2014-07-09 21:18:02 -04:00
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.show_posts = true
2014-07-09 21:18:02 -04:00
b.query = Badge::Queries::FirstLink
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
2014-07-21 22:46:31 -04:00
b.trigger = Badge::Trigger::PostRevision
b.system = true
2014-07-09 21:18:02 -04:00
end
2014-07-11 00:17:01 -04:00
Badge.seed do |b|
b.id = Badge::FirstQuote
b.default_name = "First Quote"
2014-07-11 00:17:01 -04:00
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.show_posts = true
2014-07-11 00:17:01 -04:00
b.query = Badge::Queries::FirstQuote
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
2014-07-21 22:46:31 -04:00
b.trigger = Badge::Trigger::PostRevision
b.system = true
2014-07-11 00:17:01 -04:00
end
2014-07-08 00:26:53 -04:00
Badge.seed do |b|
b.id = Badge::FirstLike
b.default_name = "First Like"
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.show_posts = true
b.query = Badge::Queries::FirstLike
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
2014-07-21 22:46:31 -04:00
b.trigger = Badge::Trigger::PostAction
b.system = true
end
Badge.seed do |b|
b.id = Badge::FirstFlag
b.default_name = "First Flag"
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.show_posts = false
b.query = Badge::Queries::FirstFlag
b.default_badge_grouping_id = BadgeGrouping::Community
2014-07-21 22:46:31 -04:00
b.trigger = Badge::Trigger::PostAction
2014-08-09 18:40:25 -04:00
b.auto_revoke = false
b.system = true
end
Badge.seed do |b|
b.id = Badge::FirstShare
b.default_name = "First Share"
2014-07-08 00:26:53 -04:00
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.show_posts = true
b.query = Badge::Queries::FirstShare
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
# don't trigger for now, its too expensive
b.trigger = Badge::Trigger::None
b.system = true
2014-07-08 00:26:53 -04:00
end
Badge.seed do |b|
b.id = Badge::Welcome
b.default_name = "Welcome"
2014-07-07 03:55:25 -04:00
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.show_posts = true
b.query = Badge::Queries::Welcome
b.default_badge_grouping_id = BadgeGrouping::Community
2014-07-21 22:46:31 -04:00
b.trigger = Badge::Trigger::PostAction
b.system = true
end
Badge.seed do |b|
b.id = Badge::Autobiographer
b.default_name = "Autobiographer"
2014-07-07 03:55:25 -04:00
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.query = Badge::Queries::Autobiographer
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
2014-07-21 22:46:31 -04:00
b.trigger = Badge::Trigger::UserChange
b.system = true
end
2014-07-07 03:55:25 -04:00
Badge.seed do |b|
b.id = Badge::Editor
b.default_name = "Editor"
2014-07-07 03:55:25 -04:00
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.query = Badge::Queries::Editor
b.default_badge_grouping_id = BadgeGrouping::Community
2014-07-21 22:46:31 -04:00
b.trigger = Badge::Trigger::PostRevision
b.system = true
2014-07-07 03:55:25 -04:00
end
2014-06-17 02:29:49 -04:00
#
# Like system badges.
like_badges = [
2014-07-07 03:55:25 -04:00
{id: 6, name: "Nice Post", type: BadgeType::Bronze, multiple: true},
{id: 7, name: "Good Post", type: BadgeType::Silver, multiple: true},
{id: 8, name: "Great Post", type: BadgeType::Gold, multiple: true}
2014-06-17 02:29:49 -04:00
]
like_badges.each do |spec|
Badge.seed do |b|
b.id = spec[:id]
b.default_name = spec[:name]
2014-06-17 02:29:49 -04:00
b.badge_type_id = spec[:type]
b.multiple_grant = spec[:multiple]
b.target_posts = true
b.show_posts = true
b.query = Badge::Queries.like_badge(Badge.like_badge_counts[spec[:id]])
b.default_badge_grouping_id = BadgeGrouping::Posting
2014-07-21 22:46:31 -04:00
b.trigger = Badge::Trigger::PostAction
b.system = true
2014-06-17 02:29:49 -04:00
end
end
Badge.where("NOT system AND id < 100").each do |badge|
new_id = [Badge.maximum(:id) + 1, 100].max
old_id = badge.id
badge.update_columns(id: new_id)
UserBadge.where(badge_id: old_id).update_all(badge_id: new_id)
end