When using MariaDB REPLACE as addition to INSERT would be nice to have here.
See:
https://mariadb.com/kb/en/library/replace/
It's just try to insert but update if exists.
and
https://mariadb.com/kb/en/library/set-transaction/#read-committed (Locking reads)
if you want a max + 1 for insert without giving double a chance where auto_increment does not work.
(If one of you know how to "INSERT ... VALUES (SELECT MAX(..)+1) ..) .." in KORMA would be nice to know!)