This change includes:
(1) update deletes older versions of inconsistent rows
(2) update drops one index and replaces it with a new unique index
(3) fixed to ensure that when it decides whether to insert or update
it uses current database state and not cached info
(4) unit tests updated to test #3
Conflicts:
lib/db/upgrade.php
version.php