IntoTheWoods/odb — Issue #40: test implementation of hook_schema_alter
Author: IntoTheWoods
Created: 2012-01-14 16:30:53+00:00
State: open

Well, I was working on a module to add fields and to adjust the schema for the 'contact' table in core. So, when I found this hook without documentation, I thought I would just post the little piece of code I used for the hook.

'varchar',
'length' => 256,
'not null' => TRUE,
'default' => '',
);
$schema['contact']['fields']['phone'] = array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
);
$schema['contact']['fields']['fax'] = array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
);
}
}
?>

But, since this hook does NOT add the fields into the database, I will also post the rest of my code in the .install file if you are interested.

$spec) {
db_add_field($ret, 'contact', $name, $spec);
}
}

/**
* Implementation of hook_uninstall().
*/
function mymodule_uninstall() {
$ret = array();
$schema['contact'] = array();
mymodule_schema_alter($schema);
foreach ($schema['contact']['fields'] as $name => $spec) {
db_drop_field($ret, 'contact', $name);
}
}
?>

All of this code added fields to the 'contact' db table, and the fields will be added to the 'contact' schema as well. I do not know who handles documentation, but hopefully this helps that effort.