Tests + Index existing data on createIndex()

Unit tests, migration tests and bugfixes detected in the tests.