Search code examples
mysqldatabasedatabase-migrationscramble

How to migrate subset of data from production to develop by scrambling sensitive data?


I like to create a tool which scrambles the production sensitive data and added it into another dev DB. I've built a couple of scripts that make random social security numbers, shift birth dates, scramble emails, etc. But I faced a problem while we have a reference for that column.

For example:- if we scramble tables tableA and TableB,

TableB have a forieng key from tableA(ssn)

 TableA
    ssn firstName                  lastName
    .......................................
    111   arun                        prasanth                 
    222   ann                         antony                   
    333   sruthy                      abc                      
    666   new                         abc     




TableB(ssn Foreign key reference)
id  ssn   Place
................
1   111   kerala
2   222   usa
3   333   ekm
5   666   chennai

Desired output should be

 TableA
    ssn firstName                  lastName
    .......................................
    999   gdfsgs                    trttr
    956   hsggghhgh                 pipip
    855   hdsgfgsddd                lklkl
    233   ghfgfggfgf                mkmk




TableB(ssn Foreign key reference)
id  ssn   Place
................
1   999   kerala
2   956   usa
3   855   ekm
5   233   chennai

Solution

  • You can either try with some scrambling tools or create an algorithm which generates something like hashcode. Your algorithm should always generate same value if the input value is same. For eg:- The Generated value of 111 should always be 999.