views:

62

answers:

6

Hi,

I'm trying to figure out how I should save an edit a user makes to their profile in a way that doesn't go live or affect the existing live data until it's approved by an admin. Have a second table for edited profiles then copy over the data on approval? Keep it all in one table and have a _tmp copy of all the fields that are editable? Is there a best practice for this?

Thanks for your thoughts.

+1  A: 

You can build a bit of workflow into your application. So to that effect, you'll have a Workflow table that will have defined various states (e.g. entered, proposed, approved, etc...).

Then you can also have a PendingChanges table that stores these proposed changes. When the the proposed change has been approved, you merge the change into the main user profile change.

AngryHacker
+2  A: 

Having a separate table sounds good to me. That way you can store only what's changed, not everything else.

John at CashCommons
I would always go with this method instead of xml serialization. It's much much simpler and therefore easier to deal with.
Chris Lively
And then you have to made DDL updates to two tables instead of one - yuck...
OMG Ponies
Old thread, but I thought I would update it with the solution I ended up going with, which was this one. Instead of queuing multiple changes, the user makes their profile changes, it goes into this separate edits table, then each subsequent visit to the edit form loads the not-yet-approved previous edit if there is one, or the profile from the main table. Each subsequent edit replaces the one before it, since I had no need to queue them.
Fo
+1  A: 

If you have many cases like this (across many different tables) you could have a TempObject table where you serialize changes to XML or some other state until they are approved.

Or if it is just the user profile table, you could have a unique key on UserID + Approved(boolean). When the user edits their data, it goes into the table as UserID, Approved = false, then to approve it, you just delete the approved one and update the not approved one to approved (in a transaction of course).

After all, you already have the structure to hold all that data - why not reuse it?

David
This might be the answer I'm looking for. I'm not keen on cluttering the db with extra tables, or any individual table with duplicate fields, but perhaps an "edits" field in the main table where I could serialize the array (why do you suggest XML?) saved from the user's form (after sanitizing). That way also I could notify the admin of pending changes if a record has a populated "edits" field.
Fo
+2  A: 

For simplicity, I will often use some 'status' column in the database to determine if a particular row is publicly viewable. In your SQL, you would then add

 WHERE status = 'published'

That works well for simple sites.

For busier sites, I suspect there is some performance gain by not having that WHERE clause. Having pending edits in a separate table would be a good option, and then you INSERT INTO ... SELECT FROM to move it to the live table.

Brandon
A: 

A second table in the same format as the first doesn't easily allow for multiple changes to be queued.

I would recommend designing a specific tructure to record each change request as a change request. Fields for who it's changing, what is changing, what to, who made the request, when, etc.

Then have code to apply the change if/when validated.

This can also then act as an easy to track audit trail.

I would not make the changes in the same table, it tighly binds the implementations together and makes later maintenance a headache. The independance reduces how closely coupled everything is, for more flexibility in the future.

Dems
+1  A: 

This seems simplest: You could add a VERSION and a STATUS field to the USERS table. Then, use the STATUS field to show the highest VERSIONed row, as appropriate. Obviously this gives you versioning of the records as well.

As long as VERSION and STATUS are indexed, they won't really slow down any display operations. Add rows will be slighly slower, as the indexes must be maintained.

ndp