Problem statement:
To always approve record updates before the changes reflect in main record. Want to try solving this problem using SQL database.
Eg. User: { "name" : "Ravi Kumar", "city" : "Bangalore" } Say we want to update the city to "Delhi" but it has to undergo approval before it reflects in the main record.
Once approved. It should show: User: { "name" : "Ravi Kumar", "city" : "Delhi" }
Required Features:
Possible Solutions:
Have a additional column "approved" in the table. All approved records will have status 1 and rest will be 0. To get the current record we have to get record with the most recent timestamp with approved=1.
Have 2 tables one which contains the main table and another for approvals. When someone approves then we make changes to the record in main table.
Questions:
How are these problems tackled in the industry?
Related questions:
What's the best way to store changes to database records that require approval before being visible?
Structure to handle changes to records that require approval
If you want to be very careful about approving changes and you expect so many changes that it is likely that more changes will be made to a record before prior changes can be approved, then your best approach would be to have a separate set of tables with one record for each proposed change.
These "pending change" records could (should) include extra information about the change transaction, such as who proposed it and when.
Your process for handling all of these changes, and especially conflicting or overlapping changes will depend on your business rules, which you haven't stated definitively. Options include:
Regarding normalized databases and joins, this presents no special problems in your case. You will join the tables containing official, approved data as you would in any case. If you want to join to an interim/pre-approved version of a record, you should create a view which reflects these changes overlapped over the official data and then join to that view.
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.