You are here

function message_digest_update_8100 in Message Digest 8

Adds indexes to the message_digest table.

File

./message_digest.install, line 92
Install and update hooks for the Message Digest module.

Code

function message_digest_update_8100() {
  $spec = [
    'fields' => [
      'id' => [
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Numeric message notification ID.',
      ],
      'mid' => [
        'description' => 'The message ID of the originating message.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'unsigned' => TRUE,
      ],
      'entity_type' => [
        'description' => 'The entity type the message pertains to. This is used for grouping digests.',
        'type' => 'varchar',
        'length' => EntityTypeInterface::ID_MAX_LENGTH,
        'not null' => TRUE,
        'default' => '',
      ],
      'entity_id' => [
        'description' => 'The entity ID the message should be grouped with.',
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => '',
        'length' => 128,
      ],
      'receiver' => [
        'description' => 'The user ID of the acting user.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'unsigned' => TRUE,
      ],
      'notifier' => [
        'description' => 'The notification method used to send the notification.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ],
      'sent' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'Boolean for whether the message has already been sent in a digest or not.',
      ],
      'timestamp' => [
        'description' => 'When the message instance was recorded.',
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ],
    ],
  ];
  $schema = \Drupal::database()
    ->schema();
  if (!$schema
    ->indexExists('message_digest', 'aggregate')) {
    $schema
      ->addIndex('message_digest', 'aggregate', [
      'timestamp',
      'sent',
      'notifier',
    ], $spec);
  }
  if (!$schema
    ->indexExists('message_digest', 'sent')) {
    $schema
      ->addIndex('message_digest', 'sent', [
      'receiver',
      'notifier',
    ], $spec);
  }
}