Rebase database test

Includes the new checks I've been making to make sure the database is well formed.