You are here

function user_schema in Drupal 8

Same name and namespace in other branches
  1. 6 modules/user/user.install \user_schema()
  2. 7 modules/user/user.install \user_schema()
  3. 9 core/modules/user/user.install \user_schema()
  4. 10 core/modules/user/user.install \user_schema()

Implements hook_schema().

File

core/modules/user/user.install, line 11
Install, update and uninstall functions for the user module.

Code

function user_schema() {
  $schema['users_data'] = [
    'description' => 'Stores module data as key/value pairs per user.',
    'fields' => [
      'uid' => [
        'description' => 'The {users}.uid this record affects.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'module' => [
        'description' => 'The name of the module declaring the variable.',
        'type' => 'varchar_ascii',
        'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH,
        'not null' => TRUE,
        'default' => '',
      ],
      'name' => [
        'description' => 'The identifier of the data.',
        'type' => 'varchar_ascii',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ],
      'value' => [
        'description' => 'The value.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
      ],
      'serialized' => [
        'description' => 'Whether value is serialized.',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => [
      'uid',
      'module',
      'name',
    ],
    'indexes' => [
      'module' => [
        'module',
      ],
      'name' => [
        'name',
      ],
    ],
    'foreign keys' => [
      'data_user' => [
        'table' => 'users',
        'columns' => [
          'uid' => 'uid',
        ],
      ],
    ],
  ];
  return $schema;
}