Moodle ER Diagram HowTo

The diagram was generated by using the reverse engineering feature of the MySQL Workbench tool using a file containing the SQL code used to install Moodle.

The SQL statements were extracted from the install.xml files from each Moodle module. This was converted from XML to SQL using a utility I wrote as a local Moodle plugin which can be found at 

https://github.com/marcusgreen/moodle_local-sqlgenerator. This utility is fairly simple and makes use of the Moodle XMLDB API.

This utility should not be used on a live Moodle site as it has had no checking for security or robustness. Note that some of the table relationships in Moodle are not strictly relational, i.e. some tables may have multiple value fields and there may be missing primary/foreign key relationships. This will result in a diagram where a table has no link to any other table.  However this process may still result in a diagram that is useful to understand the database design.

The Moodle database xml files contain field comments but the default sql code does not write these to the database during installation. To get them into the create table statements used in the diagram generation I modified the sql_generator.sql file and the xmldb_field.php files. Ask me if you want copies of the modified files (I intend to put them on github at some point)

The generation of these diagrams was done on a Windows 8.1 /Xampp machine. The reverse engineering was done with  MySQL Workbench 6.3 though I suspect it would work on other platforms. If you require a custom version of any of these diagrams and you have funding I would consider offers

Marcus Green 2016