Drupal 6's self-documenting database schema

After many previous attempts and false starts, Drupal 6's entire core database schema is now documented and cross referenced. You can view the documentation using the contributed Schema module; see the attached screenshot for a demonstration (click to enlarge). Thanks to webchick, add1sun, pwolanin, JirkaRybka, Moshe, chx, yched, and others for contributing their knowledge of the dusty corners of the schema.

If you are a module author, when you port a module to Drupal 6 and create your hook_schema() function, you should also document the schema. Doing so is easy: just add 'description' fields to each table and field in the schema structure. For example:

<?php
function mymodule_schema() {
 
$schema['mytable'] = array(
   
'description' => t('Stores whiz-bang cool data for nodes provided by the MyModule module.'),
   
'fields' => array(
     
'nid' => array(
       
'type' => 'int',
       
'not null' => TRUE,
       
'description' => t('The {node}.nid that this row is for.'),
      ),
 
// etc.
 
return $schema;
}
?>

Placing a table reference within a description inside of curly-braces causes the reference to be displayed as a hyperlink to that table's documentation on the Schema Describe page.

Comments

Frustrating... That's was my

Frustrating... That's was my initial thought trying to understand the Drupal schema. I was trying to figure out how I can enrich a "Node" with auxiliary information, and to do that properly, i.e., not by copying other's code and modifying it. So I worked a bit on understanding the Schema, and slightly more, and ...

Frustrating... That's my final thought with regard to my attempt of understanding the schema.

Not that frustrating, I had

Not that frustrating, I had to construct an ER-Diagram of 60+ tables not only the 45 tables of the basic installation as I had installed other modules. I just requires hell lots of patience and you've too see which tables are affected after you do each action. I did it in Drupal 5. Don't know how the schema is in Drupal 6.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <i> <h1> <h2> <h3> <blockquote>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options