6.x core.php hook_schema_alter(&$schema)
7.x system.api.php hook_schema_alter(&$schema)

Performs alterations to existing database schemas.

When a module modifies the database structure of another module (by changing, adding or removing fields, keys or indexes), it should implement hook_schema_alter() to update the default $schema to take its changes into account.

See hook_schema() for details on the schema definition structure.

Parameters

$schema: Nested array describing the schemas for all modules.

Return value

None.

Related topics

File

developer/hooks/core.php, line 725
These are the hooks that are invoked by the Drupal core.

Code

function hook_schema_alter(&$schema) {

  // Add field to existing schema.
  $schema['users']['fields']['timezone_id'] = array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'description' => 'Per-user timezone configuration.',
  );
}

Comments

Jaypan’s picture

To the above poster:

The name hook_schema_alter() is a little misleading in that it won't actually alter the schema of the database by making changes. Rather it is used for 'reporting' changes that have been made by a module to other module's tables. This allows certain functions (such as drupal_write_record()) to get an accurate schema definition when one module changes another's tables.