unit test and refactor database.py part 2

Add unit tests and refactor/fix/document issues related to the database.
(Part 2, because #619 grew too large.)

Related #484
Related #619

I added the new schema in latest commit. It could apply the fix for the ``ON CONFLICT`` clause. (I put a note in for this fix.)

I have to think on how to get the defaults to be ``''`` from Pythons perspective. e.g. is it as simple as checking before an insertion if values are ``''`` in python and if so, then replace them with ``"''"`` before inserting?