Created
October 30, 2014 12:38
-
-
Save zaeem/4926a463ef5bf1455841 to your computer and use it in GitHub Desktop.
This file contains 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
#KEEP-1119 | |
# This scrip corrects the birthday of users in the database table. | |
# To run the file | |
# load('app/controllers/foo.rb') | |
# Set the incorrect data in sql as | |
# update users set birthday = date('0067-12-12'); | |
# Set tge in correct data in rails console as | |
# @u = User.all.unscoped.find(1) | |
# @u.birthday = Date.parse('0009-10-07') | |
# @u.save(:validate => false) | |
# | |
# Run the script | |
User.all.unscoped.try(:each) do |user| | |
begin | |
if user.birthday && user.birthday.try(:year).to_i < 100 | |
puts "======= INCORRECT DATA ======" | |
puts user.birthday.inspect | |
user.birthday += 1900.years | |
user.save! | |
# I won't sugest this libe but still if it fails on any kind of validation then use this line | |
user.save(:validate => false) | |
puts "======= AFTER CORRECTION ======" | |
puts user.birthday.inspect | |
end | |
rescue Exception => exp | |
puts "Exception caught for #{user.inspect} and exception is #{exp.message} " | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment