Add test coverage for the PostgreSQL storage backend

**WIP - DO NOT MERGE**

Add a test suite for the PostgreSQL storage backend and, as an added bonus, fix the bugs it has uncovered.
Your lint might be broken.