Add constraints to database tables.

Incidentally this makes deleting subjects very easy :)
Made config configurable. Yes.