diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-06-15 15:50:26 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-06-15 15:50:26 +0300 |
commit | a4a85c269a4f3165914915ede4a9a7642057d105 (patch) | |
tree | d8a695ee5266185e2df656c4674c0fc5f4acf5a0 | |
parent | bb7af46d324303f086832d77128eff7c7644f172 (diff) | |
parent | b2df11856144e91c84f51e8934e10e21f4f3fa70 (diff) |
Merge branch 'seed-fu-award-emoji' into 'master'
Seed Award Emoji while seeding the database
## What does this MR do?
Lets `rake dev:setup` create award emoji on _some_ awardables. Seemed overkill to give all that privilege.
See merge request !4555
-rw-r--r-- | db/fixtures/development/15_award_emoji.rb | 33 | ||||
-rw-r--r-- | lib/gitlab/database.rb | 4 |
2 files changed, 37 insertions, 0 deletions
diff --git a/db/fixtures/development/15_award_emoji.rb b/db/fixtures/development/15_award_emoji.rb new file mode 100644 index 00000000000..baac32f2d10 --- /dev/null +++ b/db/fixtures/development/15_award_emoji.rb @@ -0,0 +1,33 @@ +Gitlab::Seeder.quiet do + emoji = Gitlab::AwardEmoji.emojis.keys + + Issue.order(Gitlab::Database.random).limit(Issue.count / 2).each do |issue| + project = issue.project + + project.team.users.sample(2).each do |user| + issue.create_award_emoji(emoji.sample, user) + + issue.notes.sample(2).each do |note| + next if note.system? + note.create_award_emoji(emoji.sample, user) + end + + print '.' + end + end + + MergeRequest.order(Gitlab::Database.random).limit(MergeRequest.count / 2).each do |mr| + project = mr.project + + project.team.users.sample(2).each do |user| + mr.create_award_emoji(emoji.sample, user) + + mr.notes.sample(2).each do |note| + next if note.system? + note.create_award_emoji(emoji.sample, user) + end + + print '.' + end + end +end diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb index 04fa6a3a5de..d76ecb54017 100644 --- a/lib/gitlab/database.rb +++ b/lib/gitlab/database.rb @@ -30,6 +30,10 @@ module Gitlab order end + def self.random + Gitlab::Database.postgresql? ? "RANDOM()" : "RAND()" + end + def true_value if Gitlab::Database.postgresql? "'t'" |