function user_schema

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

Implements hook_schema().

File

core/modules/user/user.install, line 22

Code

function user_schema() : Schema {
  $tables[] = new Table(name: 'users_data', description: 'Stores module data as key/value pairs per user.', columns: [
    Column::int(name: 'uid', description: 'The {users}.uid this record affects.', unsigned: TRUE, notNull: TRUE, default: new IntValue(0)),
    Column::varcharAscii(name: 'module', description: 'The name of the module declaring the variable.', length: DRUPAL_EXTENSION_NAME_MAX_LENGTH, notNull: TRUE, default: new StringValue('')),
    Column::varcharAscii(name: 'name', description: 'The identifier of the data.', length: 128, notNull: TRUE, default: new StringValue('')),
    Column::blob(name: 'value', description: 'The value.', size: ColumnSize::Big, notNull: FALSE),
    Column::int(name: 'serialized', description: 'Whether value is serialized.', size: ColumnSize::Tiny, unsigned: TRUE, default: new IntValue(0)),
  ], primaryKey: new PrimaryKey([
    'uid',
    'module',
    'name',
  ]), indexes: [
    new Index(name: 'module', columns: [
      'module',
    ]),
    new Index(name: 'name', columns: [
      'name',
    ]),
  ], foreignKeys: [
    new ForeignKey(name: 'data_user', foreignTable: 'users', columns: [
      'uid',
    ], foreignColumns: [
      'uid',
    ]),
  ]);
  return new Schema(type: SchemaDefinitionType::Module, name: 'user', tables: $tables);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.