Fix renaming of duplicate document names in migration
In f0a076ed and the MR before I seem to have had a faulty function for removing documents with duplicate names. This fix will correctly remove the duplicate document names and then apply the unique constraint.