fix upgrade scripts for PostgreSQL 8.4 compatibility

Existing 5.1 upgrade scripts introduced by #2191 and #2401 did *not* run with PostgreSQL 8.4. Review those PRs to see what DB changes should be made and how these were tested and ensure that this PR leaves them working correctly on both PostgreSQL 8.x and 9.x.