Converting TouchDB iOS app to CouchbaseLite

31 views
Skip to first unread message

Len Kawell

unread,
May 14, 2014, 5:03:14 PM5/14/14
to mobile-c...@googlegroups.com
I just finished converting our iOS app from TouchDB to CouchbaseLite. So far everything is working really well! 

There have been a couple of posts in this forum (https://groups.google.com/d/topic/mobile-couchbase/IUGxueNXTB8/discussion) about data conversion from TouchDB and CouchDB and I've found, as advertised, that CouchbaseLite indeed seems to happily read, write and sync our (test) users' old TouchDB database and documents just fine. 

However, I thought I'd highlight the one key must-do that I was only able to find in the response chain in that post: you must rename the "TouchDB" directory to "CouchbaseLite" or else CouchbaseLite will create a nice new empty directory and database(s), ignoring your users' existing data. In fact, you have to be sure to do this BEFORE you invoke [CBLManager sharedInstance] or it will be too late because the empty CouchbaseLite directory will already have been created.

Here is a method that I use before I invoke [CBLManager sharedInstance] (any fixes or enhancements are welcome):

// Rename the old TouchDB directory to the name CouchbaseLite expects.

-(void)renameOldDirectory {

    

    NSFileManager* fileManager = [NSFileManager defaultManager];

    

    // If old TouchDB directory exists rename to new CouchbaseLite name.

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);

    NSString* oldPath = [paths[0] stringByAppendingPathComponent:@"TouchDB"];

    

    if ([fileManager fileExistsAtPath:oldPath]) {

        

        NSString *newPath = [paths[0] stringByAppendingPathComponent:@"CouchbaseLite"];

        NSError *renameError = nil;

        [fileManager moveItemAtPath:oldPath toPath:newPath error:&renameError];

        if (renameError) {

            NSLog(@"Error renaming TouchDB directory to CouchbaseLite %@", renameError.localizedDescription);

            // handle error

        }

    }

}


Reply all
Reply to author
Forward
0 new messages