0
votes

I am in the process of designing document storage for CouchDB and would really appreciate some feedback. These documents are to represent "assets". These databases will also be synced locally to the browser via pouchdb.

Requirements:

  • Each user can have many assets
  • Users can share assets with others by providing them with a URI such as (xyz.com/some_id). Once users click this URI, they are considered to have been "joined" and are now part of a group.
  • Group users can share assets of their own with other members of the group.

My design

  • Each user will have his/her own database to store assets - let's call it "user". Each user DB will be prefixed with the his/her unique ID.
  • Shared assets will be stored in a separate database - let's call it "group". shared assets are DUPLICATED here and have an additional field for userId (to indicate creator).
  • Group database is prefixed with a unique ID just like a user database is prefixed with one too.

The reason for storing group assets in a separate database is because when pouchdb runs locally, it only knows about the current user and his/her shared assets. It does not know about other users and will should not query these "other" users' databases.

Any input would be GREATLY appreciated.

1

1 Answers

2
votes

Seems like a great design. Another alternative would be to just have one database per group ("role"), and then replicate from a user's group(s) into their local PouchDB.

That might get hairy, though, when it comes time to replicate back to the server, because you're going to have to filter the documents as they leave the user's local database, depending on which group-database they belong to. Still, you're going to have to do that on the server side anyway with your current design.

Either way is fine, honestly. The only downside of your current approach is that documents are duplicated on the server side (once per user-db and once per group-db). On the other hand, your client code becomes dead-simple, because you don't have to do any filtered replication. If you have enough space on your server not to worry about it, then I would definitely go with your approach. :)