I'm building an app in which teams can work together on projects.
The app uses pouchdb in the browser and couchdb on the server.

This is the architecture:

   - *a db per user* (= userDb): the user gets a role per project
   The user doc (= userDoc) in the _users db (= _usersDb) is not enough
   because it can't be synced to pouchdb without admin credentials. So I
   create a userDb for every user. UserDb's can be synced between pouchdb and
   couchdb using the user's credentials.
   I also have a server script that keeps the userDoc in userDb and
   _usersDb in sync by following the userDb's change feed and updating the
   userDoc in _usersDb when necessary

   - *a db per role* = projectDb's. Roles are the project names.
   The projectDb's are synced between pouchdb and couchdb using the user's
   credentials.
   The server script creates new projectDb's when it detects new roles in
   changes in the userDoc in the userDb.

When a new user signs up:

   - the server script detects the addition of a new document in the
   _usersDb
   it creates a new userDb in couchdb and writes the userDoc from _usersDb
   into userDb, deleting the _rev before
   couchdb now answers with a rev of '*1-f08290f92631a838d6775736478cb8f8*'
   for the userDoc
   - the app creates a new userDb in pouchdb
   - the app creates a new (initial) project including a new projectDb in
   pouchdb
   - the app adds the name of the project as a new role to the userDoc in
   the userDb in pouchdb
   - the server script registers the change in the userDoc as it is
   listening to the change stream of the userDb:
      - it now fetches the last version of the userDoc using "revs_info:
      true" to compare roles and analyses what roles were added or removed
      - for added roles the script creates new projectDb's
      - for removed roles the script removes the corresponding projectDb if
      no other user uses it

The server script fetching the userDoc from the userDb using "revs_info:
true" receives these two revisions:

> [ { rev: '2-3d257e7128e2c19196a478ccb791720a', status: 'available' },
>
> { rev: '*1-1566e8ad3b127d0c475b1cd08defa4a6*', status: 'missing' } ]
>
>
rev 1 is not the same as it was before!!!????

So the questions are:

   -
*Why is the first rev now '1-1566e8ad3b127d0c475b1cd08defa4a6' and not any
   more '1-f08290f92631a838d6775736478cb8f8'? *This is just a few
   milliseconds later
   -
*And why is the document missing? *No compaction of the userDb has happened
   (or did couchdb compact without me knowing?)
   - *Is there some glaring mistake in my architecture?*

I've been banging my head for quite a while now pondering this. Help is
much appreciated.

Alex

Reply via email to