Datastore tests aren't respecting the legacy_mode flag, index creation does not work on PG 8.4

This pr fixes the tests, refactors them a little bit and fixes the index error on pg 8.4.