Commit 1b35e3c1 authored by catch's avatar catch
Browse files

Issue #3365945 by larowlan, sakthi_dev, daffie, JvE, eelkeblok, borisson_:...

Issue #3365945 by larowlan, sakthi_dev, daffie, JvE, eelkeblok, borisson_: Errors: The following table(s) do not have a primary key: forum_index

(cherry picked from commit b46d0ee3)
parent 139732ef
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -161,6 +161,7 @@ function forum_schema() {
      'created' => ['created'],
      'last_comment_timestamp' => ['last_comment_timestamp'],
    ],
    'primary key' => ['nid', 'tid'],
    'foreign keys' => [
      'tracked_node' => [
        'table' => 'node',
@@ -204,3 +205,15 @@ function forum_update_10100(&$sandbox = NULL) {
    $connection->schema()->changeField('forum_index', 'last_comment_timestamp', 'last_comment_timestamp', $new);
  }
}

/**
 * Add a primary key to forum_index.
 */
function forum_update_10101(&$sandbox = NULL) {
  $connection = \Drupal::database();
  if ($connection->schema()->tableExists('forum_index')) {
    $connection->schema()->addPrimaryKey('forum_index', ['nid', 'tid']);
    return \t('Added primary key to the forum_index table.');
  }
  return \t('The forum_index table does not exist, the update was skipped.');
}
+64.1 KiB

File added.

Preview size limit exceeded, changes collapsed.

+35 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Tests\forum\Functional;

use Drupal\FunctionalTests\Update\UpdatePathTestBase;

/**
 * Tests addition of the forum_index primary key.
 *
 * @group forum
 */
final class ForumIndexUpdateTest extends UpdatePathTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setDatabaseDumpFiles() {
    $this->databaseDumpFiles = [
      dirname(__DIR__, 2) . '/fixtures/update/drupal-10.1.0.empty.standard.forum.gz',
    ];
  }

  /**
   * Tests the update path to add the new primary key.
   */
  public function testUpdatePath(): void {
    $schema = \Drupal::database()->schema();
    $this->assertFalse($schema->indexExists('forum_index', 'PRIMARY'));
    $this->runUpdates();
    $this->assertTrue($schema->indexExists('forum_index', 'PRIMARY'));
  }

}
+52 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Tests\forum\Kernel;

use Drupal\KernelTests\KernelTestBase;

/**
 * Defines a class for testing the forum_index table.
 *
 * @group forum
 */
final class ForumIndexTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'system',
    'user',
    'node',
    'history',
    'taxonomy',
    'forum',
    'comment',
    'options',
    'text',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();
    $this->installEntitySchema('node');
    $this->installEntitySchema('user');
    $this->installEntitySchema('comment');
    $this->installEntitySchema('taxonomy_term');
    $this->installSchema('forum', ['forum_index']);
  }

  /**
   * Tests there's a primary key on the forum_index table.
   */
  public function testForumIndexIndex(): void {
    $schema = \Drupal::database()->schema();
    $this->assertTrue($schema->tableExists('forum_index'));
    $this->assertTrue($schema->indexExists('forum_index', 'PRIMARY'));
  }

}