Make uniqueness check more robust

This doesn't just fail if the unique value already exists, but also
checks to see if it's different than the value currently being indexed.