chore: Generate test data for bulk insertion (#11229)
Co-authored-by: Vishnu Narayanan <vishnu@chatwoot.com> Co-authored-by: Sojan <sojan@pepalo.com> Co-authored-by: tds-1 <tanmay@qoala.id> Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
This commit is contained in:
committed by
GitHub
parent
cbdbf7900e
commit
6e6912aa56
30
lib/tasks/generate_test_data.rake
Normal file
30
lib/tasks/generate_test_data.rake
Normal file
@@ -0,0 +1,30 @@
|
||||
require_relative '../test_data'
|
||||
|
||||
namespace :data do
|
||||
desc 'Generate large, distributed test data'
|
||||
task generate_distributed_data: :environment do
|
||||
if Rails.env.production?
|
||||
puts 'Generating large amounts of data in production can have serious performance implications.'
|
||||
puts 'Exiting to avoid impacting a live environment.'
|
||||
exit
|
||||
end
|
||||
|
||||
# Configure logger
|
||||
Rails.logger = ActiveSupport::Logger.new($stdout)
|
||||
Rails.logger.formatter = proc do |severity, datetime, _progname, msg|
|
||||
"#{datetime.strftime('%Y-%m-%d %H:%M:%S.%L')} #{severity}: #{msg}\n"
|
||||
end
|
||||
|
||||
begin
|
||||
TestData::DatabaseOptimizer.setup
|
||||
TestData.generate
|
||||
ensure
|
||||
TestData::DatabaseOptimizer.restore
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Clean up existing test data'
|
||||
task cleanup_test_data: :environment do
|
||||
TestData.cleanup
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user