Cordova Web Application Using PouchDB / CouchDB Schema

I would like to use PouchDB with CouchDB because of the excellent synchronization and replication features for my web application, but I find it difficult to find a better way to simulate my data for what I need to do.

The application allows the user to create calendar events that can be shared with the users they select. Users associated with this event can add comments and make changes to this event.

1) As far as I understand, each user should have his own database in order to avoid access to other user data if all of them are stored in one db. If so, how can I update or share document data from different databases?

2) Should I manage the username on another server using the sql database with the API?

Any guidance would be greatly appreciated!

Danio

+3
source share
3 answers

If I understand your application correctly, you have documents that look something like this:

{ "_id": "event-{timestamp/name/something}", "organizer": "alice", "attendees": [ "alice", "bob", "charlie" ] } 

If this is roughly correct, I would suggest the following architecture so that it works with PouchDB and CouchDB .

The goal here is to "cut the seed" of the CouchDB replication protocol, split permissions into containers (databases per user and database per share / relationship) and provide a hidden friendly distribution / distribution model .... because the cloud sometimes leaves .;)

In the flowchart below, you can see Alice's “device” (or application, etc.) on the left. Alice stores events in the private-user-space database. Any event document (for example, above) with visitors on it is copied (possibly through a background process, a filtered replication process) to exchange databases based on user IDs used in the attendees key (or, nevertheless, you model your materials) .

Federation for Alice, Bob and Charlie

Each of these share-with-* databases is constantly (ideally) replicated to the cloudy (most likely) CouchDB (or compatible) database. Bob and Charlie have their own applications connected to the same cloud-based CouchDB database (or compatible), and the Alice event is replicated to its share-with-alice database.

The application then provides these events to Bob and Charlie, allows them to make their changes, replicates these changes back to the share-with-alice database, and then (ultimately because the network) returns to the cloud and returns to Alice.

In all of this, a cloud bit is optional .;) Depending on the deployment, it can be three devices on the same network that discover each other in a different way and are replicated as available.

From what I understand about your application, this should work. :) You mentioned that there are other comment documents, and they will need to be modeled in the same way - or the application will use its relationship with the event document to do the right thing with the appropriate comments.

I would be very interested to know if this seems like a possible path, since I myself study it for several projects.

Hope for something useful whatever. :)

+5
source

Probably the simplest in this case would be the assignment of roles and the use of the "one database for each role" model (as opposed to the "one database for each user" model).

You do not need a separate database for this. CouchDB can handle this just fine. However, to manage user permissions, role assignments, etc. You will need some server logic.

If an event can have any combination of users, it looks like you might have to do something like “one document per role,” which translates as “one document per database”. This may not be feasible if you expect users to create many documents, but keep in mind that you can always synchronize multiple remote databases with one local database (or vice versa or whatever combination you want). Good luck

0
source

I believe that there is always an ideal solution for any kind of use in the CouchDB ecosystem, but what really distracts us from this is to think that relationally complex and personal freedom is reduced due to security. The best design decisions are also the simplest. One of the simplest solutions to the stated security problem, leading to the creation of a non-circular database for each user design that I mentioned in the Couchdb / Pouchdb schematic diagram

0
source

Source: https://habr.com/ru/post/987397/


All Articles