Created
October 19, 2017 20:12
-
-
Save evmorov/a690b260b6392ad4599a1ef73fe7f6ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| log_path = File.join(File.dirname(__FILE__), 'fix_time.log') | |
| puts "Writing log to '#{log_path}'" | |
| open(log_path, 'w+') do |f| | |
| zone = '+03:00' | |
| zone_shift = 3 | |
| bug_begin_datetime = DateTime.new(2017, 10, 19, 18, 50, 00) | |
| bug_fixed_datetime = DateTime.new(2017, 10, 19, 18, 52, 30) | |
| f.puts "Zone shift is #{zone_shift}" | |
| f.puts "The code with the problem appeared at #{bug_begin_datetime}" | |
| f.puts "The code with the problem was fixed at #{bug_fixed_datetime}" | |
| f.puts '' | |
| ActiveRecord::Base.transaction do | |
| [ | |
| [CRM::Activity, :period_end], | |
| [CRM::Activity, :period_start], | |
| [Resident::MedicationOrder::DosageInstruction, :time], | |
| [CareProgram::Manipulation, :latest_end_time], | |
| [CareProgram::Manipulation, :earliest_start_time], | |
| [DutyPeriod, :end_time], | |
| [DutyPeriod, :start_time], | |
| [HRM::Employee::Activity, :time], | |
| [HRM::Shift, :end_time], | |
| [HRM::Shift, :start_time], | |
| [Resident::StayPeriod, :checkout_time], | |
| [Resident::StayPeriod, :checkin_time], | |
| [Resident::Leave, :end_time], | |
| [Resident::Leave, :start_time], | |
| [Resident::GroupActivity, :time] | |
| ].each do |class_name_with_time_column| | |
| class_name = class_name_with_time_column.first | |
| time_column = class_name_with_time_column.last | |
| f.puts "----" | |
| f.puts "#{class_name} #{time_column}" | |
| f.puts "----" | |
| f.puts '' | |
| entities_with_bug = class_name.where("created_at > ? AND updated_at < ?", bug_begin_datetime, bug_fixed_datetime) | |
| f.puts "There are #{entities_with_bug.count} entities with the bug" | |
| f.puts "ids of them: #{entities_with_bug.ids}" | |
| f.puts '' | |
| entities_with_bug.each do |entity_with_bug| | |
| time_with_bug = entity_with_bug.send(time_column) | |
| time_fixed = time_with_bug + zone_shift.hours | |
| result = entity_with_bug.update(time_column => time_fixed) | |
| if result | |
| f.puts "id #{entity_with_bug.id} fixed" | |
| else | |
| f.puts entity_with_bug.errors | |
| raise entity_with_bug.errors | |
| end | |
| end | |
| f.puts '' | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment