diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index 7b6f40f9bac..8ec203f14fd 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -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.'); +} diff --git a/core/modules/forum/tests/fixtures/update/drupal-10.1.0.empty.standard.forum.gz b/core/modules/forum/tests/fixtures/update/drupal-10.1.0.empty.standard.forum.gz new file mode 100644 index 00000000000..47d39d11298 Binary files /dev/null and b/core/modules/forum/tests/fixtures/update/drupal-10.1.0.empty.standard.forum.gz differ diff --git a/core/modules/forum/tests/src/Functional/ForumIndexUpdateTest.php b/core/modules/forum/tests/src/Functional/ForumIndexUpdateTest.php new file mode 100644 index 00000000000..70a719a89d3 --- /dev/null +++ b/core/modules/forum/tests/src/Functional/ForumIndexUpdateTest.php @@ -0,0 +1,35 @@ +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')); + } + +} diff --git a/core/modules/forum/tests/src/Kernel/ForumIndexTest.php b/core/modules/forum/tests/src/Kernel/ForumIndexTest.php new file mode 100644 index 00000000000..3c5def9853e --- /dev/null +++ b/core/modules/forum/tests/src/Kernel/ForumIndexTest.php @@ -0,0 +1,52 @@ +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')); + } + +}