Using pghistory for an optimistic concurrency check #167
-
I am looking for a solution that has both history tracking and concurrency detection (aka two different users editing the same table row).
For my use case this setup seems to be sufficient. Basically doing what django-concurrency is doing, but by using pghistory tables instead of adding extra columns. Am I forgetting something obvious? Is this something that would be good fit for pghistory? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I'd argue for using pgtrigger for something like this. For example, here's a trigger example for versioning a model on any change. You can check if the version has been updated without writing snapshots to a totally new table. If, of course, you're already writing snapshots on every change using pghistory, then you can also use the ID of the history row as a version. Are you wondering if this could go in the library? Seems better suited for a third-party tool |
Beta Was this translation helpful? Give feedback.
I'd argue for using pgtrigger for something like this. For example, here's a trigger example for versioning a model on any change. You can check if the version has been updated without writing snapshots to a totally new table.
If, of course, you're already writing snapshots on every change using pghistory, then you can also use the ID of the history row as a version. Are you wondering if this could go in the library? Seems better suited for a third-party tool