database: ensure update-or-insert is run within a transaction