Fix export of data during database migration

Closes #2927
-refactor exporter to export tables that exist in the
 database instead of keying off of schema.js
-move some shared database utility functions into their
 own module
Merge pull request #2928 from jaswilli/issue-2927-export

Fix export of data during database migration