Add db constraints

- Added not null constraints where needed
- Added several foreign key constraints
- Updated some tests