Shuffling code around so ensure_database() doesn't get duplicated N times.