Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.49k stars 589 forks source link

How to manually set the sync status of a table and its documents? #1546

Open rohankm opened 1 year ago

rohankm commented 1 year ago

Hi, How to manually set the sync status of a table and its documents?

I want to reset the sync status and re-create all the documents on the server.

lucaswitch commented 1 year ago

There is a field inside ._raw of every model like following: model._raw.status it tells watermelon which state of sync is the model.

rohankm commented 1 year ago

will changing _raw.status field re-sync the data? and will the data be created or updated in push data?

radex commented 1 year ago

I believe something like this should work:

await record.update(() => {
  // NOTE: unsafe!
  record._raw._status = 'created'
})
Dallas62 commented 1 year ago

Hi @rohankm,

I'm interested in the reason why you want to implement this reset ?

I'm experiencing some desynchronisation on my application but I'm unable to see in the code an issue. Relations trigger exception on the server side, so I was able to reset this specific entity on client side and they are now synchronized. But I just found some cases where entities without such constraints doesn't exist on server side but only on client-side.

I can implement a "checksum" to resynchronise all client data, but it's weird. If you are experiencing desynchronisation too, maybe there is an issue in the status of entity in Watermelon, @radex ?

1192

radex commented 1 year ago

@Dallas62 Check out https://github.com/Nozbe/WatermelonDB/pull/1615 , in Watermeln 0.27 there's a new diagnostics tool for finding all sync inconsistencies. That might help you in hunting for sync bugs