2

I need to update a bunch of records (200k) in my dev db, but running a query through the rails console is causing my computer to choke (partially because the console prints out the result of the query).

example:

1.9.3p194 :083 > Player.first
 => #<Player id: 1, IsActive: false, IsVisible: false, FirstName: "Ovie", LastName: "Soko", HeightFeet: 6, HeightInches: 8, Weight: 210, Birthday: nil, Gender: "M", HometownCity: "London", HometownState: "", HometownZip: "", HometownCountry: "", HighSchoolId: "", HighSchoolIdTemp: 0, HighSchoolGradYear: "2009", CollegeYear: "", Redshirted: false, Transferred: false, CollegeId: "{299F909C-88D9-4D26-8ADC-3EC1A66168BB}", CollegeIdTemp: 844, CollegeGradYear: "2013", OtherAccountId: 0, PreviousCollegeId: 0, CurrentTeamId: 0, LateralRecommendationReason: "", LateralRecommendationLink: "", CreationDate: "2011-02-16 20:53:34.877000000", CreatedBy: "", LastModifiedDate: "2011-02-16 20:53:34.877000000", LastModifiedBy: "", TwitterLink: "", FacebookLink: "", PersonalWebsite: "", PlayerImage: "", FirstNameNickName: "", NeulionID: 0, OtherTeamID: 0, OtherSportTypeID: 0, SourceDataTypeID: 1, PlayerTypeID: 2, LoadID: "", SameNameTeammate: "", SameNameSchoolMate: "", SD_SportID: 0, SD_PlayerID: 0, ZeroNCAAStats: "", ModifiedByPythonGame: "", Missing2011: "", Transfer2011: "", RecruitingClass: "\r", created_at: nil, updated_at: nil, high_school_id: nil, high_school_name: nil, not_valid: nil, city_to_zip_id: nil, user_id: nil> 

As we can see, printing 200k records would be no bueno.

I tried the solution here: Disable Rails SQL logging in console, but I still get log output after that.

1.9.3p194 :087 > old_logger = ActiveRecord::Base.logger
 => #<Logger:0x007feb04b8de58 @progname=nil, @level=1, @default_formatter=#<Logger::Formatter:0x007feb04b8dde0 @datetime_format=nil>, @formatter=#<Logger::SimpleFormatter:0x007feb04b8dc50 @datetime_format=nil>, @logdev=#<Logger::LogDevice:0x007feb04b8dcf0 @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDERR>>, @mutex=#<Logger::LogDevice::LogDeviceMutex:0x007feb04b8dcc8 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x007feb04b8dc78>>>> 
1.9.3p194 :088 > ActiveRecord::Base.logger = nil
 => nil 
1.9.3p194 :089 > Player.first
 => #<Player id: 1, IsActive: false, IsVisible: false, FirstName: "Ovie", LastName: "Soko", HeightFeet: 6, HeightInches: 8, Weight: 210, Birthday: nil, Gender: "M", HometownCity: "London", HometownState: "", HometownZip: "", HometownCountry: "", HighSchoolId: "", HighSchoolIdTemp: 0, HighSchoolGradYear: "2009", CollegeYear: "", Redshirted: false, Transferred: false, CollegeId: "{299F909C-88D9-4D26-8ADC-3EC1A66168BB}", CollegeIdTemp: 844, CollegeGradYear: "2013", OtherAccountId: 0, PreviousCollegeId: 0, CurrentTeamId: 0, LateralRecommendationReason: "", LateralRecommendationLink: "", CreationDate: "2011-02-16 20:53:34.877000000", CreatedBy: "", LastModifiedDate: "2011-02-16 20:53:34.877000000", LastModifiedBy: "", TwitterLink: "", FacebookLink: "", PersonalWebsite: "", PlayerImage: "", FirstNameNickName: "", NeulionID: 0, OtherTeamID: 0, OtherSportTypeID: 0, SourceDataTypeID: 1, PlayerTypeID: 2, LoadID: "", SameNameTeammate: "", SameNameSchoolMate: "", SD_SportID: 0, SD_PlayerID: 0, ZeroNCAAStats: "", ModifiedByPythonGame: "", Missing2011: "", Transfer2011: "", RecruitingClass: "\r", created_at: nil, updated_at: nil, high_school_id: nil, high_school_name: nil, not_valid: nil, city_to_zip_id: nil, user_id: nil> 

Is there a new hack for Rails 3.2.1 or am I doing something wrong?

Community
  • 1
  • 1
Tyler DeWitt
  • 23,366
  • 38
  • 119
  • 196

2 Answers2

2

You don't have to have the console print the result of the last statement. This is a little bit of a contrived example but you can have your last statement be nil:

irb(main):156:0> Player.update_all(:IsActive => true); nil

SQL (1.8ms)  UPDATE "players" SET "IsActive" = 't'
=> nil
John Naegle
  • 8,077
  • 3
  • 38
  • 47
0

I don't think you are doing anything wrong. Does Player.all return everything too? My guess is the output you seeing might be the Rails main logger instead of the ActiveRecord logger.

You can probably set any one of those to nil in development.rb.

EDIT:

config.logger
config.active_record.logger
config.action_controller.logger
config.action_view.logger
config.action_mailer.logger
config.active_resource.logger
Benjamin Tan Wei Hao
  • 9,621
  • 3
  • 30
  • 56