[refact #5] factor out dbname and permission checks, also add some more checks around db creation