Couchbase sync and pre-built database

Hi,

I have an app using Couchbase Lite syncing with an instance of Couchbase server.

The total size of the database is around 40MB, therefore I was wondering if there’s a way to avoid downloading the whole database from scratch when the app is launched for the first time.

Is it possible to embed a pre-built version of the database in the app?
If so, the app will be syncing only the changes made after the pre-built version of the database was exported.
That would dramatically reduce the amount of data to be exchanged between the app and the server.

Thanks

Kind regards

Below are links to both CBL 1.x & 2.x. In both instances you just point to the path in which you have stored the older DB file path.

Couchbase Lite 1.x - https://developer.couchbase.com/documentation/mobile/1.5/guides/couchbase-lite/native-api/database/index.html#story-h2-1
Couchbase Lite 2.x - http://docs.couchbase.com/mobile/2.0/couchbase-lite-swift/db022/Classes/Database.html#/s:18CouchbaseLiteSwift8DatabaseC4pathSSSgv

1 Like

Hi @househippo, if I understood well, the pre-built database should be in CBL format, right? If so, how can I export a database currently stored on Couchbase server into a CBL file?

Thanks

@PasqualePuzio,

Most people have a UAT or Pre-prod build of an App that pulls the PROD data onto a device. Then they use that copy of the CBL DB as a template for their Prod App release.

1 Like

To elaborate, if you include prebuilt version of your DB, then during initial startup, there would be something like an “empty sync” that happens with the SGW to get the CBL and SGW synced up on the state of things so subsequent changes can be replicated. During this sync, document bodies not get exchanged so it is very lightweight.

1 Like

@househippo Got it! All I have to do is to fetch the CBL file from a pre-prod build of the app.

Thank you

@priya.rajagopal thank you!

Hmmm. So, what if we want to automate the process of generation of that initial CBL file? Is it not possible? @priya.rajagopal

Not sure I get the context of this question. How you automate the process is unto you - for instance you can incorporate it into your CI/CD pipeline and bundle the generated prebuilt database into your app bundle

I want to know how to generate that prebuilt database @priya.rajagopal

@priya.rajagopal Thought of giving greater context to make things even more clear and also because this is important for our product.

So, we store all the content in couchbase server and we want our CI/CD pipeline to build our mobile applications that has the pre-built couchbase lite database also packaged in it. Every time we release a new version of the app, we want to include the latest pre-built couchbase lite database.

The original answer provided above, says that someone should run the mobile app and execute a pull replication and then pull the couchbase lite database file out of that app which is then included in another build of the app. We ship a lot of apps and we are trying to automate the process of generating that initial couchbase lite pre-built database and include that in the mobile application build pipeline.

I hope this makes things more clear. Happy to provide any more information.

A related question : Is couchbase-lite pre-built database platform agnostic i.e., can we use a pre-built database built on android as is on iOS?

Looking forward to your response.

Yes. you will need a CBL based app that will pull the data and generate the database which you can then copy over to your mobile apps. This sole purpose of this app is to generate the database - naturally, this is different than the actual mobile app (that depends on the prebuilt database).

You have several options for the CBL based app . You can create a separate mobile app or a common option is to use our cblite tool . Others have built a simple Java based app that just pulls the data and generates the database.

Note that the prebuilt database must be generated by syncing data from the Sync Gateway/couchbase server that will be used in production. The channel filters that you use in replication must also match what will eventually be used in the app.

Yes.

You can create a separate mobile app or a common option is to use our cblite tool .

So cblite cp is the command for performing the pull replication. Seems to be the simplest.

Others have built a simple Java based app that just pulls the data and generates the database.

This is good information. Creating a jvm based application to generate the pre-built database seems to be a feasible option.

Note that the prebuilt database must be generated by syncing data from the Sync Gateway/couchbase server that will be used in production. The channel filters that you use in replication must also match what will eventually be used in the app.

Ah. Thanks for adding this gotcha. Very useful.

Glad, things became more clear and you were able to help us out. Many thanks.