Skip to content
Snippets Groups Projects

Issue #3365945: Errors: The following table(s) do not have a primary key: forum_index

Closed Issue #3365945: Errors: The following table(s) do not have a primary key: forum_index
6 unresolved threads
Closed Lee Rowlands requested to merge issue/drupal-3365945:3365945-10.1.x into 10.1.x
6 unresolved threads

Merge request reports

Closed by Lee RowlandsLee Rowlands 1 year ago (Oct 5, 2023 2:36am UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
204 205 $connection->schema()->changeField('forum_index', 'last_comment_timestamp', 'last_comment_timestamp', $new);
205 206 }
206 207 }
208
209 /**
210 * Add a primary key to forum_index.
211 */
212 function forum_update_10101(&$sandbox = NULL) {
213 $connection = \Drupal::database();
214 if ($connection->schema()->tableExists('forum_index')) {
215 $connection->schema()->addPrimaryKey('forum_index', ['nid', 'tid']);
  • 19 protected function setDatabaseDumpFiles() {
    20 $this->databaseDumpFiles = [
    21 dirname(__DIR__, 2) . '/fixtures/update/drupal-10.1.0.empty.testing.forum.gz',
    22 ];
    23 }
    24
    25 /**
    26 * Tests the update path to add the new primary key.
    27 */
    28 public function testUpdatePath(): void {
    29 $schema = \Drupal::database()->schema();
    30 // We can't reliably call ::indexExists for each database driver as sqlite
    31 // doesn't have named indexes for primary keys like mysql (PRIMARY) and
    32 // pgsql (pkey).
    33 $find_primary_key_columns = new \ReflectionMethod(get_class($schema), 'findPrimaryKeyColumns');
    34 $find_primary_key_columns->setAccessible(TRUE);
  • 38 $this->installEntitySchema('comment');
    39 $this->installEntitySchema('taxonomy_term');
    40 $this->installSchema('forum', ['forum_index']);
    41 }
    42
    43 /**
    44 * Tests there's a primary key on the forum_index table.
    45 */
    46 public function testForumIndexIndex(): void {
    47 $schema = \Drupal::database()->schema();
    48 $this->assertTrue($schema->tableExists('forum_index'));
    49 // We can't reliably call ::indexExists for each database driver as sqlite
    50 // doesn't have named indexes for primary keys like mysql (PRIMARY) and
    51 // pgsql (pkey).
    52 $find_primary_key_columns = new \ReflectionMethod(get_class($schema), 'findPrimaryKeyColumns');
    53 $find_primary_key_columns->setAccessible(TRUE);
  • added 1 commit

    Compare with previous version

  • 204 205 $connection->schema()->changeField('forum_index', 'last_comment_timestamp', 'last_comment_timestamp', $new);
    205 206 }
    206 207 }
    208
    209 /**
    210 * Add a primary key to forum_index.
    211 */
    212 function forum_update_10101(&$sandbox = NULL) {
    213 $connection = \Drupal::database();
    214 if ($connection->schema()->tableExists('forum_index')) {
    215 // Identify duplicate records.
    216 $query = $connection->select('forum_index')
    217 ->fields('forum_index', ['nid', 'tid'])
    218 ->having('COUNT(*) > 1');
  • 225 ->condition('tid', $record->'tid');
    226
    227 // Get the duplicate records.
    228 $duplicateRecords = $duplicateQuery->execute()->fetchAll();
    229
    230 // Keep the first record and delete the rest.
    231 $firstRecord = true;
    232 foreach ($duplicateRecords as $duplicateRecord) {
    233 if ($firstRecord) {
    234 $firstRecord = false;
    235 continue;
    236 }
    237 // Delete the duplicate record.
    238 $connection->delete('forum_index')
    239 ->condition('nid', $record->'nid')
    240 ->condition('tid', $record->'tid');
  • 18 */
    19 protected function setDatabaseDumpFiles() {
    20 $this->databaseDumpFiles = [
    21 dirname(__DIR__, 2) . '/fixtures/update/drupal-10.1.0.empty.testing.forum.gz',
    22 ];
    23 }
    24
    25 /**
    26 * Tests the update path to add the new primary key.
    27 */
    28 public function testUpdatePath(): void {
    29 $schema = \Drupal::database()->schema();
    30 // We can't reliably call ::indexExists for each database driver as sqlite
    31 // doesn't have named indexes for primary keys like mysql (PRIMARY) and
    32 // pgsql (pkey).
    33 $find_primary_key_columns = new \ReflectionMethod(get_class($schema), 'findPrimaryKeyColumns');
  • closed

  • Please register or sign in to reply
    Loading