Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pending status style design

 
John Boby
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I have an already built project (which uses, Spring and JPA). One of the feature allows a user to add a place in the database.

I would like to setup a "pending" state system, that when a user add a new place, this place is added to the database (postgreSQL in my case)
but in a "pending state" and is not actually viewed as a final place. (then an admin will have to approve that place to make it visible to other user)

Is there any mechanism that Spring or JPA offers to archive this?
Or is the only way is to redesign the table and modify all the queries ? (And if so, what would be a good design?, adding an extra column (state) ? or having separates tables etc.. ?

Thank you!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,
A separate "pending" table is one option. Another is to use a view. You'd still need to modify your existing queries to use the view. Or move the existing data to a new table so the original name can be used as the new view name.
 
John Boby
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for replying to my question!

In my question I have simplified my problem.
While I do have a place table I also have tags and pictures(i will this one out for the moment..) that are associated to it
So At the moment I have 3 table (place,tag and pace_tag which link a place to its tags)

The first thing that came to my mind was to duplicate these 3 tables (calling them temporary_place, temporary_tag etc..) when a user add a place I would fill these 3 new table and when then admin approved them I would copy the content to the existing table.
This method as the advantage to avoid having to refactor the all project as I do not touch the existing table structure.. But is this a good design?

If this is a bad idea, and let's say i can afford to refactor the code and queries, what would be an ideal design ?

Jeanne, you are suggesting using views. Could you explain me more in how do you intend using it ? Do you mean creating a new table place with an extra column "state" (which can be an enum or etc..) and creating a view that looks like this?
create view place as select * from place where state='active'; ? (i would have moved all the content of the place table into the new table and name the view place as you suggested )

Thank you
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think either the separate tables or the modifying the queries is best. Which of the two it is would depend on how much existing code you have and whether the pending data shares constraints. If you have unique tag names and the like, there is an advantage to having them in one table.

The views should be a last resort. And yes, your understanding of the view approach is correct.

 
John Boby
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An other thing I omitted to mention, is that at the moment when adding a new place some calculation is done (on the place and tags).
Because the place will be now in a pending state it makes no sense to include it for calculation.

I actually do like this idea of using views. When you say "last resort" do you mean because it requires to much changes or because it is not commonly done ?
because the view would actually return the exact same structure.


Thank you!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not as commonly done. But it is done sometimes. My reason to avoid is that it is another thing to maintain. If I can avoid it and change the real table, I prefer that. It's not bad to use views though. Also, the view approach requires a data migration to new tables. Depending on how much data you have, this might be a pain.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic