简体   繁体   中英

Database technique for editing records and ensuring record is not updated until the record is approved

How would you handle a situation with the following scenario?

You have a table with customer records with the following fields:

id, name, email, phone
1, John, john@example.com, 515-222-3333
2, Smith, smith@example.com, 515-333-444

John opens his record and changes his phone number. However, the actual record of the customer should not be changed until the admin approves the change.

How would you handle a situation like this?

Would you?

a. Create an exact replica of customer table called customer-temp
b. Copy the record of John into customer-temp
c. let the admin review the updated record in customer-temp
d. once approved, the record is replaced with the record of john in customer table and remove John's record from customer-temp

Is this the best solution or is there a better way to handle this? Also what if customer table has a few other tables in relations?

Expert advise would be appreciated. FYI, i use Postgresql database.

----- updated format ---

I would have an additional attribute for each attribute that needs review.

In your example, the entries could be:

id, name, name_tmp, email, email_tmp, phone, phone_tmp

name would contain the approved name, name_tmp the name that has been edited by the user.
Upon approval, the contents of name_tmp are copied to name .

That way you don't have any problems with foreign key relationships.

If you really don't want the attributes in the main table, create a customer_temp table like you suggested with id as primary key and foreign key referencing customer . The downside is that you need more joins in your queries that way.

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