Issue #3365945 by larowlan, sakthi_dev, daffie, JvE, eelkeblok, borisson_: Errors: The following table(s) do not have a primary key: forum_index
parent
fb6023c3c8
commit
b46d0ee347
|
@ -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.');
|
||||
}
|
||||
|
|
BIN
core/modules/forum/tests/fixtures/update/drupal-10.1.0.empty.standard.forum.gz
vendored
Normal file
BIN
core/modules/forum/tests/fixtures/update/drupal-10.1.0.empty.standard.forum.gz
vendored
Normal file
Binary file not shown.
|
@ -0,0 +1,35 @@
|
|||
<?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'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?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'));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue