0

We would like to implement Multiversion concurrency control for our Symfony2 webapp.

This means that on any event, no UPDATE is performed on the database, but only INSERTs. As I haven't found any native support by Symfony2 for this requirement, I made up my mind how this could be implemented manually.

Besides the regular ID (primary key) of each entity (e.g. a User), we add another entity property, e.g. another userID. So on each change of the user attributes, we could simply INSERT another row for the user, which then has another ID, but the same userID.

The entity could then always be identified by the specific additional entity ID.

But there are a couple of problems that come up with this solution: The regular entity ID is the primary key and therefore the identifier for all relations to this entity. One could also try to create combined primary keys (e.g. ID plus timestamp, or ID plus entityID), but Symfony2/Doctrine2 is not constructed to support combined primary keys.

So how would you approach to implement a MVCC in Symfony2/Doctrine2? Do you see a way to handle this? Or would you recommend to use a separate history table that keeps track of all changes?

Gottlieb Notschnabel
  • 9,408
  • 18
  • 74
  • 116
  • 1
    Take a look at the [Loggable](https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/loggable.md) extension. – Emii Khaos Oct 17 '13 at 12:57
  • _but Symfony2/Doctrine2 is not constructed to support combined primary keys_ [Are you sure?](https://doctrine-orm.readthedocs.org/en/latest/tutorials/composite-primary-keys.html) – A.L Oct 17 '13 at 13:08
  • @n.1 Oh you're right. I was confusing it with [this answer](http://stackoverflow.com/a/18874646/1828051). I updated my question. Thanks for that hint! – Gottlieb Notschnabel Oct 17 '13 at 14:38
  • @Pazi, looks promising. Thanks for the hint. – Gottlieb Notschnabel Oct 18 '13 at 09:34

0 Answers0