5 use Drupal\Core\Entity\ContentEntityTypeInterface;
6 use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;
7 use Drupal\Core\Field\FieldStorageDefinitionInterface;
10 * Defines the user schema handler.
12 class UserStorageSchema extends SqlContentEntityStorageSchema {
17 protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
18 $schema = parent::getEntitySchema($entity_type, $reset);
20 $schema['users_field_data']['unique keys'] += [
21 'user__name' => ['name', 'langcode'],
30 protected function processIdentifierSchema(&$schema, $key) {
31 // The "users" table does not use serial identifiers.
32 if ($key != $this->entityType->getKey('id')) {
33 parent::processIdentifierSchema($schema, $key);
40 protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) {
41 $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping);
42 $field_name = $storage_definition->getName();
44 if ($table_name == 'users_field_data') {
45 switch ($field_name) {
47 // Improves the performance of the user__name index defined
48 // in getEntitySchema().
49 $schema['fields'][$field_name]['not null'] = TRUE;
50 // Make sure the field is no longer than 191 characters so we can
51 // add a unique constraint in MySQL.
52 $schema['fields'][$field_name]['length'] = USERNAME_MAX_LENGTH;
56 $this->addSharedTableFieldIndex($storage_definition, $schema);
61 $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);