I don't understand this comment.

But in any case, I recommend that you handle this new database case separately above and not dispatch the events when creating the db for the first time.