thebioengineer / TidyX

111 stars 45 forks source link

Multi User DB editing #14

Open J-flem opened 3 years ago

J-flem commented 3 years ago

Hi Patrick and Ellis,

Loving the series on using databases. If possible could you cover a situation where you could have multiple people simultaneously editing data from the same database.

Using the example from episode 75.

2 different coaches, in different shiny sessions that happen to be going through and providing comments on the same game at the same time. How would the following situation resolve.

(events happen in order)

  1. Both coaches (on separate machines) open up the shiny app.
  2. Both coaches are presented with pbp DT in the app that has no comments.
  3. Coach 1 adds a comment to play 1 and commits it to the db.
  4. Coach 2 then also wants to give a comment to play 1. Keeping in mind, when this coach pulled the data from the DB, there was no comment for play 1.
  5. Coach 2 then writes their comment, and presses commit.

In the above situation I think your code as of episode 75 would mean any of Coach 1's comments made between Coach 2 pulling the data from the database and Coach 2 pressing their commit button, get overwritten by Coach 2's commit.

There are a few different solutions that could work for this specific situation, give each coach a specific column, store comments made by different coaches in different tables etc.

I'm interested to see if there's a reasonable way, similar to episode 73 where you could do some sort of reactive polling to provide a way of interacting with the database in a similar vein to multiple people editing a google sheet at once etc. I understand it isn't a realistic use-case to see what other users are typing, character by character but at least something to see if the data in your session of the app is "out of date"? as in someone else has edited/commented/added to that data.

Thanks again for all your time and effort with the TidyX series!