DB: check existence before update/insert action