fix(initDB): initDB was not set up to run from the command line

Move the functionality into a lib file to aid testing.