Unverified Commit 47976dab authored by Vijay Mani's avatar Vijay Mani
Browse files

Issue #3228627 by EvanSchisler, davenelson, vijaycs85: Add entity_id_status index

parent 237d0bb2
Loading
Loading
Loading
Loading

codes_pool.install

0 → 100644
+32 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Installation functionality of the codes_pool module.
 */

use Drupal\Core\Database\Database;
use Drupal\codes_pool\Plugin\codes_pool\CodesStorage;

/**
 * Add index to codes pool tables.
 */
function codes_pool_update_8001() {
  $schema = Database::getConnection()->schema();

  $bundles = array_keys(\Drupal::service('entity_type.bundle.info')->getBundleInfo('codes_pool_collection'));
  $database_storage = new CodesStorage\Database();
  $spec = $database_storage->schemaDefinition();

  foreach ($bundles as $bundle) {
    $table = 'codes_pool_csv_' . $bundle;
    if ($schema->tableExists($table)) {
      if (!$schema->indexExists($table, 'entity_id_status')) {
        $schema->addIndex($table, 'entity_id_status', ['entity_id', 'status'], $spec);
      }
      if (!$schema->indexExists($table, 'code')) {
        $schema->addIndex($table, 'code', ['code'], $spec);
      }
    }
  }
}
+4 −4
Original line number Diff line number Diff line
@@ -196,8 +196,8 @@ class Database implements CodesStorageInterface {
   *
   * @internal
   */
  protected function schemaDefinition() {
    $schema = [
  public function schemaDefinition() {
    return [
      'description' => 'Codes pool table.',
      'fields' => [
        'id' => [
@@ -240,10 +240,10 @@ class Database implements CodesStorageInterface {
      ],
      'indexes' => [
        'status' => ['status'],
        'entity_id_status' => ['entity_id', 'status'],
        'code' => ['code']
      ],

    ];
    return $schema;
  }

}