Skip to content

Commit

Permalink
Merge pull request #1056 from couchbase/feature/fix_upgrade_localdoc
Browse files Browse the repository at this point in the history
Fixed #1041 importing local docs when upgrading the database
  • Loading branch information
snej committed Jan 23, 2016
2 parents 2f87cbe + 771e242 commit 9928d54
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Source/CBLDatabaseUpgrade.m
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ - (CBLStatus) importLocalDocs {
while (SQLITE_ROW == (err = sqlite3_step(localQuery))) {
@autoreleasepool {
NSString* docID = columnString(localQuery, 0);
// Remove "_local/" prefix:
if ([docID hasPrefix:@"_local/"])
docID = [docID substringFromIndex:7];
NSData* json = columnData(localQuery, 1);
NSDictionary* props = [CBLJSON JSONObjectWithData: json options: 0 error: NULL];
LogTo(Upgrade, @"Upgrading local doc '%@'", docID);
Expand Down
6 changes: 3 additions & 3 deletions Unit-Tests/Database_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ - (void) test24_upgradeDatabase {

// Test db contents:
[self checkReplacedDatabaseNamed: @"replacedb"
onComplete: ^(CBLDatabase* replaceDb, CBLQueryEnumerator* rows) {
onComplete: ^(CBLDatabase* targetDb, CBLQueryEnumerator* rows) {
AssertEq(rows.count, 2u);
CBLDocument* doc = [rows rowAtIndex:0].document;
AssertEqual(doc.documentID, @"doc1");
Expand All @@ -1334,8 +1334,8 @@ - (void) test24_upgradeDatabase {
AssertEq(att.length, att.content.length);

// https://github.com/couchbase/couchbase-lite-ios/issues/1041:
// NSDictionary* localDoc = [replaceDb existingLocalDocumentWithID: @"local1"];
//Assert(localDoc);
NSDictionary* localDoc = [targetDb existingLocalDocumentWithID: @"local1"];
Assert(localDoc);
}];

// Close and re-open the db using SQLite storage type. Should fail if it used to be ForestDB:
Expand Down

0 comments on commit 9928d54

Please sign in to comment.