Created
April 8, 2009 18:59
-
-
Save jondahl/91930 to your computer and use it in GitHub Desktop.
Rake task to anonymize data
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
# | |
# Copyright (c) 2009 Jonathan Dahl | |
# | |
# Released under the MIT license. See below for details. | |
# | |
namespace :db do | |
namespace :data do | |
desc "Anonymize sensitive information" | |
task :anonymize => :environment do | |
if RAILS_ENV == 'production' | |
puts "Refusing to anonymize production data. You don't really want to do that." | |
else | |
puts "Anonymizing all name and email records in the #{RAILS_ENV} database." | |
# User.find(:all).each do |user| | |
# user.name = Anonymizer.random_name | |
# user.email = Anonymizer.random_email(user.name) | |
# puts "Saving #{user.name} (#{user.email})" | |
# user.save! | |
# end | |
end | |
end | |
end | |
end | |
class Anonymizer | |
def self.random_name | |
"#{random_first_name} #{random_last_name}" | |
end | |
def self.random_first_name | |
FIRSTNAMES[rand(FIRSTNAMES.size)] | |
end | |
def self.random_last_name | |
LASTNAMES[rand(LASTNAMES.size)] | |
end | |
def self.random_email(name) | |
"#{name.downcase.gsub(" ",".")}@example.com" | |
end | |
def self.random_phone | |
"612-555-#{rand(8000) + 1000}" | |
end | |
FIRSTNAMES = %w(James | |
John | |
Robert | |
Michael | |
William | |
David | |
Richard | |
Charles | |
Joseph | |
Thomas | |
Christopher | |
Daniel | |
Paul | |
Mark | |
Donald | |
George | |
Kenneth | |
Steven | |
Edward | |
Brian | |
Ronald | |
Anthony | |
Kevin | |
Jason | |
Matthew | |
Gary | |
Timothy | |
Jose | |
Larry | |
Jeffrey | |
Frank | |
Scott | |
Eric | |
Stephen | |
Andrew | |
Raymond | |
Gregory | |
Joshua | |
Jerry | |
Dennis | |
Walter | |
Patrick | |
Peter | |
Harold | |
Douglas | |
Henry | |
Carl | |
Arthur | |
Ryan | |
Roger | |
Joe | |
Juan | |
Jack | |
Albert | |
Jonathan | |
Justin | |
Terry | |
Gerald | |
Keith | |
Samuel | |
Willie | |
Lawrence | |
Ralph | |
Nicholas | |
Roy | |
Benjamin | |
Bruce | |
Brandon | |
Adam | |
Fred | |
Harry | |
Wayne | |
Billy | |
Steve | |
Louis | |
Jeremy | |
Aaron | |
Randy | |
Eugene | |
Howard | |
Carlos | |
Russell | |
Bobby | |
Victor | |
Martin | |
Ernest | |
Phillip | |
Todd | |
Jesse | |
Craig | |
Alan | |
Shawn | |
Chris | |
Clarence | |
Philip | |
Sean | |
Johnny | |
Earl | |
Jimmy | |
Antonio | |
Bryan | |
Danny | |
Tony | |
Mary | |
Patricia | |
Linda | |
Barbara | |
Elizabeth | |
Jennifer | |
Maria | |
Susan | |
Margaret | |
Dorothy | |
Lisa | |
Nancy | |
Karen | |
Betty | |
Helen | |
Sandra | |
Donna | |
Carol | |
Ruth | |
Sharon | |
Michelle | |
Laura | |
Sarah | |
Kimberly | |
Deborah | |
Jessica | |
Shirley | |
Cynthia | |
Angela | |
Melissa | |
Brenda | |
Amy | |
Anna | |
Rebecca | |
Virginia | |
Kathleen | |
Pamela | |
Martha | |
Debra | |
Amanda | |
Stephanie | |
Carolyn | |
Christine | |
Janet | |
Marie | |
Catherine | |
Frances | |
Ann | |
Joyce | |
Diane | |
Alice | |
Julie | |
Heather | |
Teresa | |
Doris | |
Gloria | |
Evelyn | |
Cheryl | |
Jean | |
Katherine | |
Mildred | |
Joan | |
Ashley | |
Judith | |
Rose | |
Janice | |
Kelly | |
Nicole | |
Judy | |
Christina | |
Kathy | |
Theresa | |
Beverly | |
Denise | |
Tammy | |
Irene | |
Jane | |
Lori | |
Rachel | |
Marilyn | |
Andrea | |
Kathryn | |
Louise | |
Sara | |
Anne | |
Jacqueline | |
Wanda | |
Bonnie | |
Julia | |
Ruby | |
Lois | |
Tina | |
Phyllis | |
Norma | |
Paula | |
Annie | |
Diana | |
Lillian | |
Emily | |
Peggy | |
Robin) | |
LASTNAMES = %w( | |
Abbott | |
Acevedo | |
Acosta | |
Adams | |
Adkins | |
Aguilar | |
Aguirre | |
Albert | |
Alexander | |
Alford | |
Allen | |
Allison | |
Alston | |
Alvarado | |
Alvarez | |
Anderson | |
Andrews | |
Anthony | |
Armstrong | |
Arnold | |
Ashley | |
Atkins | |
Atkinson | |
Austin | |
Avery | |
Avila | |
Ayala | |
Ayers | |
Bailey | |
Baird | |
Baker | |
Baldwin | |
Ball | |
Ballard | |
Banks | |
Barber | |
Barker | |
Barlow | |
Barnes | |
Barnett | |
Barr | |
Barrera | |
Barrett | |
Barron | |
Barry | |
Bartlett | |
Barton | |
Bass | |
Bates | |
Battle | |
Bauer | |
Baxter | |
Beach | |
Bean | |
Beard | |
Beasley | |
Beck | |
Becker | |
Bell | |
Bender | |
Benjamin | |
Bennett | |
Benson | |
Bentley | |
Benton | |
Berg | |
Berger | |
Bernard | |
Berry | |
Best | |
Bird | |
Bishop | |
Black | |
Blackburn | |
Blackwell | |
Blair | |
Blake | |
Blanchard | |
Blankenship | |
Blevins | |
Bolton | |
Bond | |
Bonner | |
Booker | |
Boone | |
Booth | |
Bowen | |
Bowers | |
Bowman | |
Boyd | |
Boyer | |
Boyle | |
Bradford | |
Bradley | |
Bradshaw | |
Brady | |
Branch | |
Bray | |
Brennan | |
Brewer | |
Bridges | |
Briggs | |
Bright | |
Britt | |
Brock | |
Brooks | |
Brown | |
Browning | |
Bruce | |
Bryan | |
Bryant | |
Buchanan | |
Buck | |
Buckley | |
Buckner | |
Bullock | |
Burch | |
Burgess | |
Burke | |
Burks | |
Burnett | |
Burns | |
Burris | |
Burt | |
Burton | |
Bush | |
Butler | |
Byers | |
Byrd | |
Cabrera | |
Cain | |
Calderon | |
Caldwell | |
Calhoun | |
Callahan | |
Camacho | |
Cameron | |
Campbell | |
Campos | |
Cannon | |
Cantrell | |
Cantu | |
Cardenas | |
Carey | |
Carlson | |
Carney | |
Carpenter | |
Carr | |
Carrillo | |
Carroll | |
Carson | |
Carter | |
Carver | |
Case | |
Casey | |
Cash | |
Castaneda | |
Castillo | |
Castro | |
Cervantes | |
Chambers | |
Chan | |
Chandler | |
Chaney | |
Chang | |
Chapman | |
Charles | |
Chase | |
Chavez | |
Chen | |
Cherry | |
Christensen | |
Christian | |
Church | |
Clark | |
Clarke | |
Clay | |
Clayton | |
Clements | |
Clemons | |
Cleveland | |
Cline | |
Cobb | |
Cochran | |
Coffey | |
Cohen | |
Cole | |
Coleman | |
Collier | |
Collins | |
Colon | |
Combs | |
Compton | |
Conley | |
Conner | |
Conrad | |
Contreras | |
Conway | |
Cook | |
Cooke | |
Cooley | |
Cooper | |
Copeland | |
Cortez | |
Cote | |
Cotton | |
Cox | |
Craft | |
Craig | |
Crane | |
Crawford | |
Crosby | |
Cross | |
Cruz | |
Cummings | |
Cunningham | |
Curry | |
Curtis | |
Dale | |
Dalton | |
Daniel | |
Daniels | |
Daugherty | |
Davenport | |
David | |
Davidson | |
Davis | |
Dawson | |
Day | |
Dean | |
Decker | |
Dejesus | |
Delacruz | |
Delaney | |
Deleon | |
Delgado | |
Dennis | |
Diaz | |
Dickerson | |
Dickson | |
Dillard | |
Dillon | |
Dixon | |
Dodson | |
Dominguez | |
Donaldson | |
Donovan | |
Dorsey | |
Dotson | |
Douglas | |
Downs | |
Doyle | |
Drake | |
Dudley | |
Duffy | |
Duke | |
Duncan | |
Dunlap | |
Dunn | |
Duran | |
Durham | |
Dyer | |
Eaton | |
Edwards | |
Elliott | |
Ellis | |
Ellison | |
Emerson | |
England | |
English | |
Erickson | |
Espinoza | |
Estes | |
Estrada | |
Evans | |
Everett | |
Ewing | |
Farley | |
Farmer | |
Farrell | |
Faulkner | |
Ferguson | |
Fernandez | |
Ferrell | |
Fields | |
Figueroa | |
Finch | |
Finley | |
Fischer | |
Fisher | |
Fitzgerald | |
Fitzpatrick | |
Fleming | |
Fletcher | |
Flores | |
Flowers | |
Floyd | |
Flynn | |
Foley | |
Forbes | |
Ford | |
Foreman | |
Foster | |
Fowler | |
Fox | |
Francis | |
Franco | |
Frank | |
Franklin | |
Franks | |
Frazier | |
Frederick | |
Freeman | |
French | |
Frost | |
Fry | |
Frye | |
Fuentes | |
Fuller | |
Fulton | |
Gaines | |
Gallagher | |
Gallegos | |
Galloway | |
Gamble | |
Garcia | |
Gardner | |
Garner | |
Garrett | |
Garrison | |
Garza | |
Gates | |
Gay | |
Gentry | |
George | |
Gibbs | |
Gibson | |
Gilbert | |
Giles | |
Gill | |
Gillespie | |
Gilliam | |
Gilmore | |
Glass | |
Glenn | |
Glover | |
Goff | |
Golden | |
Gomez | |
Gonzales | |
Gonzalez | |
Good | |
Goodman | |
Goodwin | |
Gordon | |
Gould | |
Graham | |
Grant | |
Graves | |
Gray | |
Green | |
Greene | |
Greer | |
Gregory | |
Griffin | |
Griffith | |
Grimes | |
Gross | |
Guerra | |
Guerrero | |
Guthrie | |
Gutierrez | |
Guy | |
Guzman | |
Hahn | |
Hale | |
Haley | |
Hall | |
Hamilton | |
Hammond | |
Hampton | |
Hancock | |
Haney | |
Hansen | |
Hanson | |
Hardin | |
Harding | |
Hardy | |
Harmon | |
Harper | |
Harrell | |
Harrington | |
Harris | |
Harrison | |
Hart | |
Hartman | |
Harvey | |
Hatfield | |
Hawkins | |
Hayden | |
Hayes | |
Haynes | |
Hays | |
Head | |
Heath | |
Hebert | |
Henderson | |
Hendricks | |
Hendrix | |
Henry | |
Hensley | |
Henson | |
Herman | |
Hernandez | |
Herrera | |
Herring | |
Hess | |
Hester | |
Hewitt | |
Hickman | |
Hicks | |
Higgins | |
Hill | |
Hines | |
Hinton | |
Hobbs | |
Hodge | |
Hodges | |
Hoffman | |
Hogan | |
Holcomb | |
Holden | |
Holder | |
Holland | |
Holloway | |
Holman | |
Holmes | |
Holt | |
Hood | |
Hooper | |
Hoover | |
Hopkins | |
Hopper | |
Horn | |
Horne | |
Horton | |
House | |
Houston | |
Howard | |
Howe | |
Howell | |
Hubbard | |
Huber | |
Hudson | |
Huff | |
Huffman | |
Hughes | |
Hull | |
Humphrey | |
Hunt | |
Hunter | |
Hurley | |
Hurst | |
Hutchinson | |
Hyde | |
Ingram | |
Irwin | |
Jackson | |
Jacobs | |
Jacobson | |
James | |
Jarvis | |
Jefferson | |
Jenkins | |
Jennings | |
Jensen | |
Jimenez | |
Johns | |
Johnson | |
Johnston | |
Jones | |
Jordan | |
Joseph | |
Joyce | |
Joyner | |
Juarez | |
Justice | |
Kane | |
Kaufman | |
Keith | |
Keller | |
Kelley | |
Kelly | |
Kemp | |
Kennedy | |
Kent | |
Kerr | |
Key | |
Kidd | |
Kim | |
King | |
Kinney | |
Kirby | |
Kirk | |
Kirkland | |
Klein | |
Kline | |
Knapp | |
Knight | |
Knowles | |
Knox | |
Koch | |
Kramer | |
Lamb | |
Lambert | |
Lancaster | |
Landry | |
Lane | |
Lang | |
Langley | |
Lara | |
Larsen | |
Larson | |
Lawrence | |
Lawson | |
Le | |
Leach | |
Leblanc | |
Lee | |
Leon | |
Leonard | |
Lester | |
Levine | |
Levy | |
Lewis | |
Lindsay | |
Lindsey | |
Little | |
Livingston | |
Lloyd | |
Logan | |
Long | |
Lopez | |
Lott | |
Love | |
Lowe | |
Lowery | |
Lucas | |
Luna | |
Lynch | |
Lynn | |
Lyons | |
MacDonald | |
Macias | |
Mack | |
Madden | |
Maddox | |
Maldonado | |
Malone | |
Mann | |
Manning | |
Marks | |
Marquez | |
Marsh | |
Marshall | |
Martin | |
Martinez | |
Mason | |
Massey | |
Mathews | |
Mathis | |
Matthews | |
Maxwell | |
May | |
Mayer | |
Maynard | |
Mayo | |
Mays | |
McBride | |
McCall | |
McCarthy | |
McCarty | |
McClain | |
McClure | |
McConnell | |
McCormick | |
McCoy | |
McCray | |
McCullough | |
McDaniel | |
McDonald | |
McDowell | |
McFadden | |
McFarland | |
McGee | |
McGowan | |
McGuire | |
Mcintosh | |
McIntyre | |
McKay | |
McKee | |
McKenzie | |
McKinney | |
McKnight | |
McLaughlin | |
McLean | |
McLeod | |
McMahon | |
McMillan | |
McNeil | |
McPherson | |
Meadows | |
Medina | |
Mejia | |
Melendez | |
Melton | |
Mendez | |
Mendoza | |
Mercado | |
Mercer | |
Merrill | |
Merritt | |
Meyer | |
Meyers | |
Michael | |
Middleton | |
Miles | |
Miller | |
Mills | |
Miranda | |
Mitchell | |
Molina | |
Monroe | |
Montgomery | |
Montoya | |
Moody | |
Moon | |
Mooney | |
Moore | |
Morales | |
Moran | |
Moreno | |
Morgan | |
Morin | |
Morris | |
Morrison | |
Morrow | |
Morse | |
Morton | |
Moses | |
Mosley | |
Moss | |
Mueller | |
Mullen | |
Mullins | |
Munoz | |
Murphy | |
Murray | |
Myers | |
Nash | |
Navarro | |
Neal | |
Nelson | |
Newman | |
Newton | |
Nguyen | |
Nichols | |
Nicholson | |
Nielsen | |
Nieves | |
Nixon | |
Noble | |
Noel | |
Nolan | |
Norman | |
Norris | |
Norton | |
Nunez | |
Obrien | |
Ochoa | |
Oconnor | |
Odom | |
Odonnell | |
Oliver | |
Olsen | |
Olson | |
Oneal | |
Oneil | |
Oneill | |
Orr | |
Ortega | |
Ortiz | |
Osborn | |
Osborne | |
Owen | |
Owens | |
Pace | |
Pacheco | |
Padilla | |
Page | |
Palmer | |
Park | |
Parker | |
Parks | |
Parrish | |
Parsons | |
Pate | |
Patel | |
Patrick | |
Patterson | |
Patton | |
Paul | |
Payne | |
Pearson | |
Peck | |
Pena | |
Pennington | |
Perez | |
Perkins | |
Perry | |
Peters | |
Petersen | |
Peterson | |
Petty | |
Phelps | |
Phillips | |
Pickett | |
Pierce | |
Pittman | |
Pitts | |
Pollard | |
Poole | |
Pope | |
Porter | |
Potter | |
Potts | |
Powell | |
Powers | |
Pratt | |
Preston | |
Price | |
Prince | |
Pruitt | |
Puckett | |
Pugh | |
Quinn | |
Ramirez | |
Ramos | |
Ramsey | |
Randall | |
Randolph | |
Rasmussen | |
Ratliff | |
Ray | |
Raymond | |
Reed | |
Reese | |
Reeves | |
Reid | |
Reilly | |
Reyes | |
Reynolds | |
Rhodes | |
Rice | |
Rich | |
Richard | |
Richards | |
Richardson | |
Richmond | |
Riddle | |
Riggs | |
Riley | |
Rios | |
Rivas | |
Rivera | |
Rivers | |
Roach | |
Robbins | |
Roberson | |
Roberts | |
Robertson | |
Robinson | |
Robles | |
Rocha | |
Rodgers | |
Rodriguez | |
Rodriquez | |
Rogers | |
Rojas | |
Rollins | |
Roman | |
Romero | |
Rosa | |
Rosales | |
Rosario | |
Rose | |
Ross | |
Roth | |
Rowe | |
Rowland | |
Roy | |
Ruiz | |
Rush | |
Russell | |
Russo | |
Rutledge | |
Ryan | |
Salas | |
Salazar | |
Salinas | |
Sampson | |
Sanchez | |
Sanders | |
Sandoval | |
Sanford | |
Santana | |
Santiago | |
Santos | |
Sargent | |
Saunders | |
Savage | |
Sawyer | |
Schmidt | |
Schneider | |
Schroeder | |
Schultz | |
Schwartz | |
Scott | |
Sears | |
Sellers | |
Serrano | |
Sexton | |
Shaffer | |
Shannon | |
Sharp | |
Sharpe | |
Shaw | |
Shelton | |
Shepard | |
Shepherd | |
Sheppard | |
Sherman | |
Shields | |
Short | |
Silva | |
Simmons | |
Simon | |
Simpson | |
Sims | |
Singleton | |
Skinner | |
Slater | |
Sloan | |
Small | |
Smith | |
Snider | |
Snow | |
Snyder | |
Solis | |
Solomon | |
Sosa | |
Soto | |
Sparks | |
Spears | |
Spence | |
Spencer | |
Stafford | |
Stanley | |
Stanton | |
Stark | |
Steele | |
Stein | |
Stephens | |
Stephenson | |
Stevens | |
Stevenson | |
Stewart | |
Stokes | |
Stone | |
Stout | |
Strickland | |
Strong | |
Stuart | |
Suarez | |
Sullivan | |
Summers | |
Sutton | |
Swanson | |
Sweeney | |
Sweet | |
Sykes | |
Talley | |
Tanner | |
Tate | |
Taylor | |
Terrell | |
Terry | |
Thomas | |
Thompson | |
Thornton | |
Tillman | |
Todd | |
Torres | |
Townsend | |
Tran | |
Travis | |
Trevino | |
Trujillo | |
Tucker | |
Turner | |
Tyler | |
Tyson | |
Underwood | |
Valdez | |
Valencia | |
Valentine | |
Valenzuela | |
Vance | |
Vang | |
Vargas | |
Vasquez | |
Vaughan | |
Vaughn | |
Vazquez | |
Vega | |
Velasquez | |
Velazquez | |
Velez | |
Villarreal | |
Vincent | |
Vinson | |
Wade | |
Wagner | |
Walker | |
Wall | |
Wallace | |
Waller | |
Walls | |
Walsh | |
Walter | |
Walters | |
Walton | |
Ward | |
Ware | |
Warner | |
Warren | |
Washington | |
Waters | |
Watkins | |
Watson | |
Watts | |
Weaver | |
Webb | |
Weber | |
Webster | |
Weeks | |
Weiss | |
Welch | |
Wells | |
West | |
Wheeler | |
Whitaker | |
White | |
Whitehead | |
Whitfield | |
Whitley | |
Whitney | |
Wiggins | |
Wilcox | |
Wilder | |
Wiley | |
Wilkerson | |
Wilkins | |
Wilkinson | |
William | |
Williams | |
Williamson | |
Willis | |
Wilson | |
Winters | |
Wise | |
Witt | |
Wolf | |
Wolfe | |
Wong | |
Wood | |
Woodard | |
Woods | |
Woodward | |
Wooten | |
Workman | |
Wright | |
Wyatt | |
Wynn | |
Yang | |
Yates | |
York | |
Young | |
Zamora | |
Zimmerman) | |
end | |
# Copyright (c) 2009 Jonathan Dahl | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in | |
# all copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
# THE SOFTWARE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment