In one of our apps we have a data storage feature that runs on Couchbase Lite 1.2, not replicated to any server, local only. It’s been dormant for a while but we finally want to upgrade the Couchbase library. It seems the db format is too old though, I can open the database without error but
CouchbaseLiteSwift reports zero documents in the one (default) collection that it finds, however I can see 38 documents in
docs in our test database.
cblite command line tools version 2.8 and 3.1 won’t open the old database because:
database is in an old file format that can’t be opened (1/27)
What’s the best way for me to upgrade/migrate the old db version? Do I need to use a specific old (2.x?) couchbase lite library first? Anything else before I try running SQL manually to create an export file format that we can then import with the new library?
Wow. That’s a long time ago.
I’m afraid none of us have attempted anything like this. We have several suggestions for things that might work. First, of course, copy that database somewhere safe!
- Sync the database through a Sync Gateway, between the old app (v1.2) and a new app using v3.1.
- Using the v1.2 library, export the entire database as JSON documents and import them in to a v3.1 app. This will NOT transfer blobs: those will have to be done separately
- Try binding both the v1.2 and v3.1 versions of the CBL libraries in a single app. None of us know whether this will work or not… but it would make things really easy if it did.
Let us know how you fare!!
Thank you Blake! Yeah it seems like I’ll have to build an older iOS version, I’m currently trying to get them to build but boy, lots of errors to fix. I’m planning to link the old version to an app extension that simply does an export if it detects an old db version, we have a custom import/export format in place.
Is there some kind of compatibility matrix, which version of the database works with which CBL version? I don’t even know how to check which version the database has, how can I tell?
Ok… I have another suggestion:
On further inquiry, I find that any of the current Couchbase Lite platforms should be able to open that file. You should, for instance, be able to write a trivial Java program that opens that DB and closes it again, using Couchbase Lite Java 3.1.3. Simply doing that should update the database.
We have yet to officially stop supporting any old database formats. While the (utterly unsupported) cblite tool may get confused, our official library should not.
Give it a try. If it doesn’t work let us know and we’ll pursue the failure.
Thanks Blake! This is what I assumed and I’ve tried opening the database with CouchbaseLite (Swift) 3.1.3. The
Database class says the database exists and I can open it, I can see there’s a
_default collection now but when I query that for all document IDs, I get zero results. Peeking into the sqlite db myself there should be more than 30. I get no error, so I was just assuming the format is not compatible.
Here’s what I’m doing (part of a unit test) and the output I’m getting:
let name = "favorites"
let directory = Bundle(for: Self.self).bundleURL
print(":: trying to open “\(name)” at “\(directory)”") // points to the parent containing the "favorites.cblite2" directory
let exists = Database.exists(withName: name, inDirectory: directory.standardizedFileURL.absoluteString)
print(":: DB exists: \(exists)") // "...exists: true"
var config = DatabaseConfiguration()
config.directory = directory.standardizedFileURL.absoluteString
let db = try Database(name: name, config: config)
let collection = try db.defaultCollection()
let query = QueryBuilder
let results = try query.execute()
print(":: query got at least \(results.underestimatedCount) results")
// ...got at least 0 results"
When I iterate over the results, no iteration is performed.
To be clear, we’re trying to update an iOS app that is in production and users have data in that app, it’s not just one file I’m trying to update.
First of all, CBL’s ResultSet Swift class doesn’t implement underestimatedCount and the default implementation from the Sequence protocol will return 0. You may try the following.
- Check the number of docs by calling collection.count.
- From the query, you can do rs.allResults().count.
Yes, thanks pasin. I figured that out by running another unit test that adds a document. I am iterating over the results of the opened database but there’s nothing when opening that database. After I insert a document, only that one is returned.
Oooh, but this actually worked! It seems there were 2 mistakes contributing to me not seeing any results:
- I was using a
Bundle(...).bundleURL, which resulted in a new database being created somewhere, even though printing that URL/path looked correct. Switching to
Bundle(...).bundlePath makes it actually open the database for the unit test
- I tried to iterate directly over the result set, adding
allResults() now works and I can see the old documents!
Thank you both for getting me back on track. Now I have to check whether attachments/blobs still work (the
attachments folder in the cblite2 folder was title cased to
Attachments and the blobs were renamed, so something happened), and it seems the actual documents were moved into the