3 namespace Drupal\comment;
5 use Drupal\Core\Entity\ContentEntityTypeInterface;
6 use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;
7 use Drupal\Core\Field\FieldStorageDefinitionInterface;
10 * Defines the comment schema handler.
12 class CommentStorageSchema extends SqlContentEntityStorageSchema {
17 protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
18 $schema = parent::getEntitySchema($entity_type, $reset);
20 $schema['comment_field_data']['indexes'] += [
21 'comment__status_pid' => ['pid', 'status'],
22 'comment__num_new' => [
31 'comment__entity_langcode' => [
45 protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) {
46 $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping);
47 $field_name = $storage_definition->getName();
49 if ($table_name == 'comment_field_data') {
50 // Remove unneeded indexes.
51 unset($schema['indexes']['comment_field__pid__target_id']);
52 unset($schema['indexes']['comment_field__entity_id__target_id']);
54 switch ($field_name) {
56 // Improves the performance of the comment__num_new index defined
57 // in getEntitySchema().
58 $schema['fields'][$field_name]['not null'] = TRUE;
62 $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
66 $this->addSharedTableFieldForeignKey($storage_definition, $schema, 'users', 'uid');