Fix data migration script

The data migration didn't handle the case when a document had been
marked as deleted. This tweaks the script so that deleted documents
are also cleared from the database.