particlebanana/sails-postgresql — pull request #8 by polastre (2013-07-22 18:36:15+00:00)
Title: Support Soft Deletes in postgresql adapter

"Soft Deletes" are commonly used in major database projects to preserve a history of all actions that have occurred.

I've updated the postgresql adapter in 5 ways:
(1) Add an option called softDelete (default set to false) to enable the softDelete functionality
(2) On table creation, add a new column called deletedAt
(3) On delete, instead of calling DELETE, set deletedAt to the current time NOW()
(4) On find, if softDelete is enabled, add to the where clause a check to filter out non-null deletedAt rows
(5) Add a unit test

Arguably #1 and 2 should be in Waterline and not in the postgresql adapter; however, I didn't want to fork both Waterline and sails-postgresql. In the case of #2, this would logically reside in schema.js/addAutoAttributes() around line 143. Putting these in Waterline would require that the other adapters also be updated, which is a larger task.

#4 could be expanded with an additional option (something like showDeleted: true) so that models could be queried for their deleted elements (useful for allowing users to revert accidental deletes). This would be a future feature request.