MDL-38314 repository: Remove orphan repository instances
MDL-38314 repository: Delete repository instances on context deletion
MDL-38314 repository: Unit Tests for delete_all_for_context()
MDL-38314 repository: Improving performance of upgrade script