On Jul 7, 2015, at 1:22 PM, Brendan Duddridge <bren...@gmail.com> wrote:I currently have all my data in a single database file. But I'm contemplating splitting it up into two database files. One to store all my metadata and another to store all my regular data. Will there be any complications with this setup in terms of synchronization or just general management of both databases?
I'm thinking that I can just have a couple of CBLManagers, each managing a separate database file.
When I want to write to one or the other, I'll just create my CBLModel objects to save to the specific database file the documents were created in. I think it should work, but I'm not sure what will happen when it comes to syncing.
The regular, non-metadata database will reference objects in the other database file, but I don't think that should be a problem since there's no foreign key relationships in Couchbase anyway as it's all managed in the application.
In any CBLModel subclass that has a property that’s a reference to a document in the other database, you’ll need to override -databaseForModelProperty:, so that it knows which database to look up the docID in.
On Jul 7, 2015, at 3:39 PM, Brendan Duddridge <bren...@gmail.com> wrote:I know I could probably do this in code by reading all the metadata separately from the regular data and dumping it to a separate file, but it would be super easy to simply copy the metadata database independently of the regular data database and bang, you have an empty database with everything setup already for you ready to enter your regular data.
I think you’d be better off writing it to a different file. That way you control the file format and exactly what the file contains. Couchbase Lite database files aren’t really meant as an interchange format; they’re more of an implementation detail of how the data gets stored locally.
On Jul 7, 2015, at 10:29 PM, Brendan Duddridge <bren...@gmail.com> wrote:Well I'm actually embedding the database into an NSDocument/UIDocument NSFileWrapper (kind of like a UIManagedDocument) so users can share the actual document files if they like
That makes me nervous for a number of reasons…
* A user can move a document at any time, but there is no support in Couchbase Lite for a database being moved while it’s open. I don’t know if SQLite can handle this without hand-holding; I know ForestDB can’t. And the CBLManager and the attachment store both keep absolute paths and assume they don’t change.
* Every database has a unique ID that’s used as part of storing checkpoints for replication. If you copy a document containing a database, you now have two copies of the same database, with the same UUID (which is no longer unique). That’s going to mess up checkpointing because both instances of the database will try to store the same checkpoint on the server. This isn’t fatal, but it will greatly slow down replication, because when it happens the replicator has to ignore the checkpoint and start over from scratch.
* Databases may internally store sensitive information like login session cookies, as part of the replicator’s saved state.
On Jul 7, 2015, at 11:43 PM, Brendan Duddridge <bren...@gmail.com> wrote:The NSDocument's setFileURL method will be called if the document is moved by another process, so I was going to override this and close the database and re-set the CBLManager's URL and re-open it with the new URL.
This could be problematic even without a document based database. A user could easily copy the same database file to multiple devices and then start replication.
Does the replicator automatically detect this situation and automatically start replication from scratch? That would be ok if it did I think. Although I don't know if the replicator would set a new unique UUID for one of the databases so maybe this will be constantly problematic.
On Jul 8, 2015, at 10:56 PM, Brendan Duddridge <bren...@gmail.com> wrote:
In my app I allow users to make a backup copy of their database from one device and restore it to another if they wish. My app just makes a zip file of the sqlite file and any file attachments. I'd like to do the same with Couchbase Lite. The user can make a backup file on iOS and restore to Mac or vice versa. I'd like to be able to keep that functionality.
There's a replaceUUIDs method on CBLDatabase that seems like it would be perfect for this scenario.
Although what would happen on the server side if the client databases suddenly had different UUIDs? Does the server keep track of the UUIDs for each device?