Created
September 7, 2012 14:43
-
-
Save simplyb/3666769 to your computer and use it in GitHub Desktop.
multi-threaded scrubbin
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
namespace :data do | |
MyApp::RakeData.tables.each do |table| | |
desc "scrubs #{table} table data" | |
task "scrub_#{table}" do | |
string_attributes = table.classify.constantize.columns.map {|c| c.name if [:string, :text].include?(c.type) }.compact | |
setters = [] | |
update_string = "UPDATE #{table} SET " | |
string_attributes.each do |attribute| | |
setters << "#{attribute}=SUBSTRING('#{MyApp::RakeData::HILARIOUS_STRING}',1,LENGTH(#{attribute}))" | |
end | |
update_string += setters.join(",") | |
begin | |
ActiveRecord::Base.connection.execute(sql) | |
puts "#{table} successfully scrubbed." | |
rescue Exception => e | |
raise "Failed: #{e}" | |
end | |
end | |
end | |
multitask :multi_scrub => MyApp::RakeData.multitask_prereqs do | |
puts "All tables have been scrubbed!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment