Factored out the db stuff so test and app can share