Fix logic in NoteDbMigrator#canSkipPrimaryStorageMigration

The ReviewDb needs to be unwrapped at this point, since reads are
enabled. This happened to pass tests, since the exception case returned
true, i.e. it assumed it was safe to skip a change. This logic was also
wrong: we should not assume it is safe to skip a change unless we have
definitively proven it, which in the case of an exception we have not.

Change-Id: Iec8d2f04bb77a02e49c7ba9629330ab62a99939b
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/notedb/rebuild/NoteDbMigrator.java b/gerrit-server/src/main/java/com/google/gerrit/server/notedb/rebuild/NoteDbMigrator.java
index 216e95a..c11aeef 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/notedb/rebuild/NoteDbMigrator.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/notedb/rebuild/NoteDbMigrator.java
@@ -667,10 +667,10 @@
    */
   private static boolean canSkipPrimaryStorageMigration(ReviewDb db, Change.Id id) {
     try {
-      return Iterables.isEmpty(db.patchSets().byChange(id));
+      return Iterables.isEmpty(unwrapDb(db).patchSets().byChange(id));
     } catch (Exception e) {
-      log.error("Error checking if change " + id + " is corrupt, assuming yes", e);
-      return true;
+      log.error("Error checking if change " + id + " can be skipped, assuming no", e);
+      return false;
     }
   }