DEV: Reintroduce chat rake dev generate tasks (#21164)

This is to help generate random channels and chat
messages for local dev. This was removed in 12a18d4d553b6c11a7f45f686ab699aa72c3312f
presumably because it was not worth refactoring at the
time.

I've only added these tasks:

- `rake chat:message:populate\[113,20\]` (channel_id, count)
  - Generates the count of messages for a channel ID provided,
    otherwise uses a random channel and 200 count.
- `rake chat:category_channel:populate`
  - Creates a chat channel for a random category.
- `rake chat🧵populate\[132,5\]` (channel_id, message_count)
  - Creates a thread with N messages in the specified channel,
    and enables threading in that channel if necessary
This commit is contained in:
Martin Brennan
2023-04-20 10:53:10 +10:00
committed by GitHub
parent 86204fa4f0
commit 6442bbf46c
5 changed files with 182 additions and 3 deletions

View File

@ -37,7 +37,7 @@ module DiscourseDev
raise 'To run this rake task in a production site, set the value of `ALLOW_DEV_POPULATE` environment variable to "1"'
end
unless ignore_current_count
unless ignore_current_count || @ignore_current_count
if current_count >= @count
puts "Already have #{current_count} #{type} records"
@ -68,8 +68,8 @@ module DiscourseDev
model.count
end
def self.populate!(*args)
self.new(*args).populate!
def self.populate!(**args)
self.new(**args).populate!
end
def self.random(model, use_existing_records: true)