title: CoreData detect database inconsistency on start up
body: <p>We have some code to determine if there is no database file currently created. If this is the case, we do some initialization routines to populate the user's database based on some files that may exist on the file system (basically a migration routine).</p>
  
  <p>The routine is basically like this</p>
  
  <pre><code>NSURL * defaultStorePath = [NSPersistentStore MR_defaultLocalStoreUrl];
  BOOL initializeDatabase = ![[NSFileManager defaultManager] fileExistsAtPath:[defaultStorePath path]];    
  
  [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreAtURL:defaultStorePath];
  
  if(initializeDatabase)
      // ... ingest user files ...
  </code></pre>
  
  <p>So this works well if the <code>.sqlite</code> file is not present. However if the <code>.sqlite-wal</code> or <code>.sqlite-shm</code> files are missing/corrupt, we can't find a way to detect this scenario.</p>
  
  <p>We would like to do a data integrity check or something in this case.</p>