Major data loss during data transfer after application update

Two days ago, I released the application. According to reviews on the AppStore and itunesconnect crash reports, there are a lot of crashes on startup. But not 100% of the users were affected, perhaps only 30%.

I read the crash logs and saw the problem. It crashed into the DB migration process. I use easy database migration. Usually I add a new version of datamodel very carefully. Even before each release, I install the previous version of the application, use it for some time, and only then do I install the latest version above it. So it was this time.

I looked at two datamodels (previous and present). Were added:

1) New objects (this is normal for easy migration)
2) New fields inside existing objects. All of them are optional. (OK for lightweight migration)
3) One new field in an existing object, which I made optional and indexed. (OK?)

None of the existing fields and objects have been renamed.


What have I done wrong?


Stack trace:

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0:
0   libsystem_kernel.dylib          0x352f439c pread + 20
1   libsqlite3.dylib                0x30d2d632 unixRead
2   libsqlite3.dylib                0x30d4221a readDbPage
3   libsqlite3.dylib                0x30d41156 sqlite3PagerAcquire
4   libsqlite3.dylib                0x30d583be moveToChild
5   libsqlite3.dylib                0x30d8e0e8 moveToLeftmost
6   libsqlite3.dylib                0x30d59582 sqlite3BtreeNext
7   libsqlite3.dylib                0x30d54328 sqlite3VdbeExec
8   libsqlite3.dylib                0x30d4f6c2 sqlite3_step
9   CoreData                        0x329e8e2e _execute
10  CoreData                        0x329e8d64 -[NSSQLiteConnection execute]
11  CoreData                        0x32a8bd54 -[NSSQLConnection prepareAndExecuteSQLStatement:]
12  CoreData                        0x32add63c -[_NSSQLiteStoreMigrator performMigration:]
13  CoreData                        0x32ad42b8 -[NSSQLiteInPlaceMigrationManager migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:]
14  CoreData                        0x32a79c02 -[NSMigrationManager migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:]
15  CoreData                        0x32ac5bf4 -[NSStoreMigrationPolicy(InternalMethods) migrateStoreAtURL:toURL:storeType:options:withManager:error:]
16  CoreData                        0x32ac519c -[NSStoreMigrationPolicy migrateStoreAtURL:withManager:metadata:options:error:]
17  CoreData                        0x32ac6b58 -[NSStoreMigrationPolicy(InternalMethods) _gatherDataAndPerformMigration:]
+3
source share
2 answers

, .xcversion? Core Data "" . , V1, V2 V3, V3 , V1 . , " " V1 V2, V2 V3. , " " , .

+2

V3 , VC V2 xcdatamodel , V1 V2. , V1, , , , .

, , Xcode , , . V1 → ...- > Vm- > Vn, , Vn. xcdatamodeld .

, Core Data, , : V1- > Vn, V2- > Vn,..., Vm- > Vn. .

, , .

~ 6 ( , , v1 App Store). , , Core Data .

:

NSURL *sourceURL = /* exercise for reader */, *destinationURL = /* exercise */;

NSManagedObjectModel *source = [[NSManagedObjectModel alloc] initWithContentsOfURL:sourceURL];
NSManagedObjectModel *destination = [[NSManagedObjectModel alloc] initWithContentsOfURL:sourceURL];

NSError *mappingError;
NSMappingModel *inferred = [NSMappingModel inferredMappingModelForSourceModel:source destinationModel:destination error:&mappingError];

, inferred!= nil, , , mappingError.

. , , .

+1

All Articles