1 system.api.php hook_schema_0()

Define the database schema to use when a module is installed during updates.

This hook is called when installing a module during the update or upgrade process. It creates the initial database schema for the newly installed module before any of its update hooks are called.

Unlike hook_schema(), when modules are installed during the update process, all hook_update_N for the module will be invoked after the database table(s) defined by this hook are created. This means that the schema definition provided here may be modified later by hook_update_N.

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

Return value

array: A schema definition structure array. For each element of the array, the key is a table name and the value is a table structure definition.

See also

hook_schema()

hook_schema_alter()

Related topics

File

core/modules/system/system.api.php, line 2773
Hooks provided by Backdrop core and the System module.

Code

function hook_schema_0() {
  $schema['my_module'] = array(
    'description' => 'The base table for my_module.',
    'fields' => array(
      'my_module_id' => array(
        'description' => 'The primary identifier for my_module.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'title' => array(
        'description' => 'The title column of my_module.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'description' => array(
        'description' => 'The description column of my_module.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array('my_module_id'),
  );
  return $schema;
}