I have a users
table that has the following fields: userid, phone, and address
. Since this is user data, I'm letting the user change them whenever he wants. Problem is I'd like to keep track of those changes and preserve the old data too. Here's some of the ideas I considered:
appending the new data to the old data and using a separator like a pipe. When retrieving the field, I would check for the existence of that separator and if exists, get the chars after it as the new data. (feels cumbersome and doesn't feel right)
setting up a different
changes
table with the following fields:userid, fieldname, fieldcontent
. When/if a user changes data (any data), I would log the event in this separate table under the user's userid, and the name/id of the field and the old content of the field, then I can now overwrite his old data inusers
with the new. If I want to find all changes made by this user, I would search thechanges
table by his userid. Problem with this is that I'm mixing all data changes (of all fields) into one table and so thefieldcontent
field inchanges
has to be text to accommodate the varying field types. This still seems better than the first idea, but still not sure if I'm doing the right thing.
What other ideas are there or known best practices to keep old data?
Thanks in advance