SMF2 to discourse - Troubles importing attachments

I’ve had that trouble before, and fixed it with the code below. For some reason, it always fails on the first connection, but it’ll catch the lost connection and try again.

  def mysql_query(sql)
    @client.query(sql, cache_rows: true)
  rescue Exception => e
    puts '=' * 50
    puts "problem with database. Trying again in 5"
    sleep 5
    puts e.message
    @client = Mysql2::Client.new(
      host: DB_HOST,
      username: DB_USER,
      password: DB_PW,
      database: DB_NAME
    )
    @client.query(sql, cache_rows: true)
  end