Sqlite and Mysql synchronization

Asked

Viewed 740 times

7

I have an application in which I have a database using Sqlite and an external service using Mysql. Basically it’s a task application, where I can create a task in mode offline. When the user has internet he already automatically send to Mysql.

inserir a descrição da imagem aqui

I have to do the synchronisation treatment and I’m having trouble solving it.

USER 1

  • Create a task
  • Synchronize the task with external bank

USER 2

  • Check for tasks in the external bank
  • Synchronize tasks

Problem

After user 2 (USER 2) completes his task, he must make the sync again with Mysql, and successively user 1 (USER 1) has to receive also this update in its database.

In the most simplified way possible, the tables would be:

tbl_task no Sqlite

  • id_internal------------( unico identifier for internal control)
  • task-------------( task name )
  • status---------------( status of completion of the pending/completed task)
  • id_usuario-------------( user who will perform the task )
  • id_author---------------( task creator user )
  • id_external--------------( external identifier if already syphonized )

tbl_task in Mysql

  • id----------------------( unico identifier )
  • task-------------( task name )
  • status---------------( status of completion of the pending/completed task)
  • id_usuario-------------( user who will perform the task )
  • id_author---------------( task creator user )

My initial idea would be to create a column in the table with the name SYNC, in which I would have control whether it was synchronized or not. However USER 2 complete a task, such as the USER 1 verify that conclusion?

  • 3

    Instead of recording only one SYNC field, why don’t you also use a last update of the kind TIMESTAMP ? Thus, when the user updates the task data, he saves that data in the database. Thus, when synchronizing the data, if the locally stored task has a lower TIMESTAMP than the external database, it is because it is outdated, therefore it needs to be synchronized.

1 answer

1

You can create a scheduled task in the App to perform the query at the base and check if there are new users.

There are two concepts here, one in which everyone consults the server to find out if there has been an update of the data and a second in which the server is the one who notifies everyone that the data has been updated. Both concepts have their advantages and disadvantages, the first being easier to apply and the second brings more performance to the application. See for example the Node.js and the Firebase.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.