Skip to content

Instantly share code, notes, and snippets.

@simplyb
Created September 7, 2012 14:43
Show Gist options
  • Save simplyb/3666769 to your computer and use it in GitHub Desktop.
Save simplyb/3666769 to your computer and use it in GitHub Desktop.
multi-threaded scrubbin
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