I'm aware that this PR did not introduce this - nevertheless ...

The inserts and updates below will fail if the database has been changed in parallel by another request.

We need to use an insert or update construct here