Ecohackerfarm / powerplant

Optimize and assist planning your garden
Other
85 stars 21 forks source link

Updates done by admin don't get synchronized to clients #67

Closed petteripitkanen closed 5 years ago

petteripitkanen commented 5 years ago

Fixing #63 by #66 introduced a bug when admin tries to edit the database after the initial npm run migrate, for some reason their changes don't get synchronized to clients.

gljivar commented 5 years ago

I have tried to check this in following way:

  1. Remove most of json plants to have a set of 10 elements
  2. I have also added extraction of _id element as it says that bulkDocs should have _id. _id and _rev become Key. If I don't extract _id, then running multiple migrations causes duplicates being added to indexed db
  3. Clear storage in client
  4. Run migrate and refresh UI- indexed db got populated in ui
  5. Run migrate - indexed db elements were not additionally duplicated
  6. Change property of one object in json file and run migrate and refresh UI two times - new object got added, with same _id and different _rev part, so new Key in total. In UI, only new object is visible
  7. Updated same element in UI and saved, refresh UI one time- new object got added, with same _id and different _rev part, so new Key got added. In UI, only new object is visible
  8. Change property of same object in json file and run migrate and refresh UI two times - new object got added, with same _id and different _rev part, so new Key in total. In UI, only new object is visible

Based on this I believe that npm run migrate is updating indexed database even with admin credentials, if json file objects get changed. But I am not sure if this should be working in this way, however it might shed a light on how to solve issue.

petteripitkanen commented 5 years ago

Thanks, indeed it seems if admin directly edits server database then there is no problem and the changes do get synchronized to clients. This works:

  1. curl -X GET http://localhost:8080/db/crops/ID to get current json of a crop
  2. curl -H 'Content-Type: application/json' -X PUT http://admin:admin@localhost:8080/db/crops/ID -d 'edited-json-here'

This stopped working after admin user and design document were set for the database:

  1. npm run cli -- pouch-clone
  2. npm run cli -- pouch-update ID --document=property:value
  3. npm run cli -- pouch-sync

I'm guessing there is some problem with pouchdb when using local databases on Node.