DB patch supersede/deprecate logic repairs; unit tests

* Fix some thinkos in the various DB functions for calculating
  supersedes/deprecation logic.

* Added a pgtap test

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Stamping upgrade script for supsersede/deprecate logic fixes

Signed-off-by: Mike Rylander <mrylander@gmail.com>