Start creating a database interface [#3141]
Closes #3141 (closed). Start updating the database model to generate public interfaces and private structs, so that alternate implementations can be plugged in, including mocks for tests.
Changelog: refactor