Commit 32732bcb authored by catch's avatar catch
Browse files

Issue #3494471 by tgauges, smustgrave: Renaming a table containing "drupal_" ...

Issue #3494471 by tgauges, smustgrave: Renaming a table containing "drupal_"  in the name with multiple indexes fails on PostreSQL

(cherry picked from commit cbfd48e0)
parent 42de5b1d
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -575,7 +575,7 @@ public function renameTable($table, $new_name) {
      // exceed the 63 chars limit of PostgreSQL, we need to take care of that.
      // cSpell:disable-next-line
      // Example (drupal_Gk7Su_T1jcBHVuvSPeP22_I3Ni4GrVEgTYlIYnBJkro_idx).
      if (str_contains($index->indexname, 'drupal_')) {
      if (str_starts_with($index->indexname, 'drupal_')) {
        preg_match('/^drupal_(.*)_' . preg_quote($index_type, NULL) . '/', $index->indexname, $matches);
        $index_name = $matches[1];
      }
+29 −0
Original line number Diff line number Diff line
@@ -365,6 +365,35 @@ public function testRenameTableWithNewIndexNameEqualsTableName(): void {
    $this->assertTrue($this->schema->tableExists($table_name_new));
  }

  /**
   * Tests renaming a table which name contains drupal_ with multiple indexes.
   */
  public function testRenameTableWithNameContainingDrupalUnderscoreAndMultipleIndexes(): void {
    $table_name_old = 'field_drupal_foo';
    $table_name_new = 'field_drupal_bar';
    $table_specification = [
      'fields' => [
        'one'  => [
          'type' => 'int',
          'default' => NULL,
        ],
        'two'  => [
          'type' => 'int',
          'default' => NULL,
        ],
      ],
      'indexes' => [
        'one' => ['one'],
        'two' => ['two'],
      ],
    ];
    $this->schema->createTable($table_name_old, $table_specification);

    $this->schema->renameTable($table_name_old, $table_name_new);

    $this->assertTrue($this->schema->tableExists($table_name_new));
  }

  /**
   * Tests column name escaping in field constraints.
   */