cwsaylor (owner)

Revisions

gist: 8429 Download_button fork
public
Description:
data_scrub.rake
Public Clone URL: git://gist.github.com/8429.git
Embed All Files: show embed
data_scrub.rake #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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