简体   繁体   中英

Architecture to merge user accounts in application

In currently running version of my application, I do not have any constraint on the uniqueness of user's phone number. It means, one phone number can be linked with multiple accounts. Only unique constrained is user's email id.

scenario 1: User registers with email Id and phone number => we create a new user record in Database respecting uniqueness of email. scenario 2: User registers with only number => we create a new user record in Database with a unique dummy-email that I generate.

In both of these scenarios , I maintain the uniqueness on email but ignore any such constraint on phone-number.

Now I need to maintain uniqueness property on both email and phone-number. So, I need to merge both the user accounts (dummy-email and real email) that share the same phone-number.

The problem is that both of these accounts can have multiple references at multiple places in Database. What should be the approach to merge two accounts together?

edit: I'm using MongoDB at backend. It generates '_id' field for every document and uses it as a primary key for that document. So, this '_id' field is served as a foreign key for that user document to rest of the database.

one sample document in users collections where user has a verified email =>

{
    _id: ObjectId("5d443787f86f9a3dfa782a3c"),
    name: 'user name',
    email: 'VerifiedUserEmail@gmail.com',
    phone_number: '1234567890'
}

another sample document in users collections where user is having duplicate phone-number =>

{
    _id: ObjectId("5c9a1146c89b2d09740ccd17"),
    name: 'dummy user name',
    email: 'DummyUserEmail@dummy-emails.com',
    phone_number: '1234567890'
}

There are really two things you can do here, either create a level of indirection (a mapping table which maps IDs together which you query at runtime), or you will have to update all the other places you reference that ID.

Personally I'd consider just doing the update, and deleting the old record. It will give you the opportunity to decide on a case-by-case how to merge the records. Simply updating the foreign key will likely create a lot of weird cartesians that you are not expecting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM