Skip to content

Instantly share code, notes, and snippets.

@cwsaylor
Created September 2, 2008 16:44
Show Gist options
  • Save cwsaylor/8429 to your computer and use it in GitHub Desktop.
Save cwsaylor/8429 to your computer and use it in GitHub Desktop.
data_scrub.rake
# Scrub your production data for use in your development/staging environments. Sets all passwords to 12345
# and email addresses to your email address in the format of email+id@domain.com. Gmail (among others) allow
# you to add extra info to your email address with a +.
require 'digest/sha1'
class DBConn < ActiveRecord::Base
ActiveRecord::Base.configurations = YAML::load(File.open(File.join(RAILS_ROOT, 'config', 'database.yml')))
ENV['RAILS_ENV'] ||= 'development'
ActiveRecord::Base.establish_connection(ENV['RAILS_ENV'])
end
namespace :data do
desc "Scrub data of personal details setting email addresses to email+id@domain.com and password to 12345. Pass NEW_EMAIL as an env var."
task :scrub => :environment do
email = ENV['NEW_EMAIL'].split("@")
# Update with your password encryption scheme
password = Digest::SHA1.hexdigest("12345")
# Update with your users table
DBConn.connection.update("UPDATE users SET password = '#{password}', email=CONCAT('#{email[0]}+', id, '@#{email[1]}')")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment