Tweak to database and add error checking when opening database

Added a "database_info" table which contains a database version.
Added a bunch of checks when opening a database, including a
check that it is the correct version. Also made added a couple
of constraints to the database.