Only regenerate the database if necessary