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 if ($data_table = $this->storage->getDataTable()) {
21 $schema[$data_table]['indexes'] += [
22 'comment__status_pid' => ['pid', 'status'],
23 'comment__num_new' => [
32 'comment__entity_langcode' => [
47 protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) {
48 $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping);
49 $field_name = $storage_definition->getName();
51 if ($table_name == 'comment_field_data') {
52 // Remove unneeded indexes.
53 unset($schema['indexes']['comment_field__pid__target_id']);
54 unset($schema['indexes']['comment_field__entity_id__target_id']);
56 switch ($field_name) {
58 // Improves the performance of the comment__num_new index defined
59 // in getEntitySchema().
60 $schema['fields'][$field_name]['not null'] = TRUE;
64 $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
68 $this->addSharedTableFieldForeignKey($storage_definition, $schema, 'users', 'uid');