How to get md5 from a record and check if it is unique?

0

I have an atypical need where several records are imported per lot, these records do not have unique identifiers, each record has information about a debt.

I'm planning to create a md5 of each record so there is no duplicity. Of course I would remove the date fields as created_at and updated_at .

I thought about using Digest::MD5.hexdigest where I would create a md5 column and before saving would check if there is an identical record.

I wonder if anyone here has ever had a similar challenge and possible solutions to this challenge. Thank you.

    
asked by anonymous 15.02.2017 / 19:23

1 answer

0

Are you persisting this data in a database? Why not let the task of knowing if it is unique to the bank? You can place a unique key in the column that you want to force the index to be. Until you make it your primary key (PK) instead of an integer ID. In fact Rails usually gives a little more work if a PK is not defined.

In case of using MD5, I think it is possible but I see many solutions using UUID. PostgreSQL (if you are using it) comes with build-in solutions to generate both MD5 and UUID.

    
14.07.2017 / 19:04