mardi 22 décembre 2015

Android SQLite and server database 2 way sync offline

My database structure is:

enter image description here


I want to sync it both ways between my android SQLite and server using a sync adapter.

The android application can perform all CRUD operations and the website can do the same thing.

The website will use the server database. Currently I use PostgreSQL but it can be changed.

The mobile app will use its own local database.

How can I sync them? The big problem is with the primary key.

  1. One of the ideas is to use uuid as primary keys but there are performance issues, because as you can see there are some join I need to perform to get from the user to other tables.

  2. Another idea is to leave the primary key as auto increment integers and use uuid columns only for syncing. But this adds a new table column for each primary and foreign key in each table.

  3. Last one is to use a compound key as primary. This one will include 3 columns user_id, id (origin database id) and device_id (website / mobile app etc). And the same thing for each foreign key.

Are there any better solutions ? If no which of mine solutions sould I use ?

How does Gmail, Keep, Dropbox or other applications performs this kind of task?


Thank you.

Aucun commentaire:

Enregistrer un commentaire