NodeStorageSchema.php 2.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
<?php

/**
 * @file
 * Contains \Drupal\node\NodeStorageSchema.
 */

namespace Drupal\node;

use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\Schema\SqlContentEntityStorageSchema;

/**
 * Defines the node schema handler.
 */
class NodeStorageSchema extends SqlContentEntityStorageSchema {

  /**
   * {@inheritdoc}
   */
  protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
    $schema = parent::getEntitySchema($entity_type, $reset);

    // Marking the respective fields as NOT NULL makes the indexes more
    // performant.
    $schema['node_field_data']['fields']['changed']['not null'] = TRUE;
    $schema['node_field_data']['fields']['created']['not null'] = TRUE;
    $schema['node_field_data']['fields']['default_langcode']['not null'] = TRUE;
    $schema['node_field_data']['fields']['promote']['not null'] = TRUE;
    $schema['node_field_data']['fields']['status']['not null'] = TRUE;
    $schema['node_field_data']['fields']['sticky']['not null'] = TRUE;
    $schema['node_field_data']['fields']['title']['not null'] = TRUE;
    $schema['node_field_revision']['fields']['default_langcode']['not null'] = TRUE;

    // @todo Revisit index definitions in https://drupal.org/node/2015277.
    $schema['node_revision']['indexes'] += array(
      'node__langcode' => array('langcode'),
    );
    $schema['node_revision']['foreign keys'] += array(
      'node__revision_author' => array(
        'table' => 'users',
        'columns' => array('revision_uid' => 'uid'),
      ),
    );

    $schema['node_field_data']['indexes'] += array(
      'node__changed' => array('changed'),
      'node__created' => array('created'),
      'node__default_langcode' => array('default_langcode'),
      'node__langcode' => array('langcode'),
      'node__frontpage' => array('promote', 'status', 'sticky', 'created'),
      'node__status_type' => array('status', 'type', 'nid'),
      'node__title_type' => array('title', array('type', 4)),
    );

    $schema['node_field_revision']['indexes'] += array(
      'node__default_langcode' => array('default_langcode'),
      'node__langcode' => array('langcode'),
    );

    return $schema;
  }

}