Fix bug update db atomically