I am continuing to work on improving my database schema. The latest version (for Moodle 3.1) includes an additional 50 PK/FK relationships which I have annotated here
https://github.com/marcusgreen/moodle_local-sqlgenerator/blob/master/morekeys.xml
Which should give some help when forming queries.
You can see the diagram here.