0

In rails, I wrote a task for automatically generate fake user

task fake_user: :environment do
  User.destroy_all
  filelink = "" 
    Dir.glob("#{Rails.root}/public/avatar/admin.jpg").map do |pic|
      client = FilestackClient.new('ARz3g0HLfR5i0KuobcdJmz')
      filelink = client.upload(filepath: pic)
  end    
  admin = User.create(
      email: "admin@example.com",
      password: "admin123", 
      role: 'admin', 
      name: 'admin',
      introduction: FFaker::Lorem::sentence(30), 
      avatar: filelink.url
    )
  puts admin.name
  20.times do |i|
    name = FFaker::Name::first_name
    filelink = "" 
    Dir.glob("#{Rails.root}/public/avatar/user#{i+1}.jpg").map do |pic|
      client = FilestackClient.new('ARz3g0HLfR5i0KuobcdJmz')
      filelink = client.upload(filepath: pic)
    end            

    user = User.create(
      name: name,
      email: "#{name}@example.co",
      password: "12345678",
      introduction: FFaker::Lorem::sentence(30),                
      avatar: filelink.url      
    )

    user.save!
    puts user.name

  end
end

And there's no error when running in local.

But when I deploy it to Heroku, some errors happened

Here's the steps I did

  1. Heroku run bundle install (correct)
  2. Heroku run rails db:migrate (correct)
  3. Heroku run rails dev:fake_user (error...)

Here's the error message I got

enter image description here

Hope someone can help me fix this.... thanks....

Adamlin0708
  • 131
  • 10

1 Answers1

0

From logs it seems that your connection is disconnected. Have you tried following in database.yml ? reconnect: true

Shani
  • 2,433
  • 2
  • 19
  • 23