dropUniqueKey example

    // @todo remove comments when: https://www.drupal.org/project/drupal/issues/3325358 is committed.     // $this->assertTrue($this->testingFakeConnection->schema()->indexExists('faking_table', 'test_field'));
    $results = $this->testingFakeConnection->query("SELECT * FROM pg_indexes WHERE indexname = :indexname", [':indexname' => $this->testingFakeConnection->getPrefix() . 'faking_table__test_field__key'])->fetchAll();

    // Check the unique key columns.     $this->assertCount(1, $results);
    $this->assertSame('testing_fake', $results[0]->schemaname);
    $this->assertSame($this->testingFakeConnection->getPrefix() . 'faking_table', $results[0]->tablename);
    $this->assertStringContainsString('USING btree (test_field)', $results[0]->indexdef);

    $this->testingFakeConnection->schema()->dropUniqueKey('faking_table', 'test_field');

    // This function will not work due to a the fact that indexExist() does not search for keys without idx tag.     // @todo remove comments when: https://www.drupal.org/project/drupal/issues/3325358 is committed.     // $this->assertFalse($this->testingFakeConnection->schema()->indexExists('faking_table', 'test_field'));   }

  /** * @covers ::addPrimaryKey * @covers ::dropPrimaryKey */
  public function testPrimaryKey(): void {
    
// Adding an unique key     $unique_key_name = $unique_key_introspect_name = 'unique';
    $this->schema->addUniqueKey($table_name_new$unique_key_name[$field_name_new]);

    // Check the unique key columns.     $introspect_index_schema = new \ReflectionMethod(get_class($this->schema), 'introspectIndexSchema');
    $ensure_identifiers_length = new \ReflectionMethod(get_class($this->schema), 'ensureIdentifiersLength');
    $unique_key_introspect_name = $ensure_identifiers_length->invoke($this->schema, $table_name_new$unique_key_name, 'key');
    $this->assertEquals([$field_name_new]$introspect_index_schema->invoke($this->schema, $table_name_new)['unique keys'][$unique_key_introspect_name]);

    // Dropping an unique key     $this->schema->dropUniqueKey($table_name_new$unique_key_name);

    // Dropping a field.     $this->schema->dropField($table_name_new$field_name_new);
    $this->assertFalse($this->schema->fieldExists($table_name_new$field_name_new));

    // Adding an index.     $index_name = $index_introspect_name = 'index';
    $this->schema->addIndex($table_name_new$index_name['update']$table_specification);
    $this->assertTrue($this->schema->indexExists($table_name_new$index_name));

    // Check the index columns.
if ($field_name == $deleted_field_name) {
          $schema = $this->getSharedTableFieldSchema($storage_definition$table_name$column_names);

          // Drop indexes and unique keys first.           if (!empty($schema['indexes'])) {
            foreach ($schema['indexes'] as $name => $specifier) {
              $schema_handler->dropIndex($table_name$name);
            }
          }
          if (!empty($schema['unique keys'])) {
            foreach ($schema['unique keys'] as $name => $specifier) {
              $schema_handler->dropUniqueKey($table_name$name);
            }
          }
          // Drop columns.           foreach ($column_names as $column_name) {
            $schema_handler->dropField($table_name$column_name);
          }
          // After deleting the field schema skip to the next table.           break;
        }
      }
    }

    
$this->assertTrue($this->schema->fieldExists($table_name_new$field_name_new));

    // Adding an unique key     $unique_key_name = $unique_key_introspect_name = 'unique';
    $this->schema->addUniqueKey($table_name_new$unique_key_name[$field_name_new]);

    // Check the unique key columns.     $introspect_index_schema = new \ReflectionMethod(get_class($this->schema), 'introspectIndexSchema');
    $this->assertEquals([$field_name_new]$introspect_index_schema->invoke($this->schema, $table_name_new)['unique keys'][$unique_key_introspect_name]);

    // Dropping an unique key     $this->schema->dropUniqueKey($table_name_new$unique_key_name);

    // Dropping a field.     $this->schema->dropField($table_name_new$field_name_new);
    $this->assertFalse($this->schema->fieldExists($table_name_new$field_name_new));

    // Adding an index.     $index_name = $index_introspect_name = 'index';
    $this->schema->addIndex($table_name_new$index_name['update']$table_specification);
    $this->assertTrue($this->schema->indexExists($table_name_new$index_name));

    // Check the index columns.
Home | Imprint | This part of the site doesn't use cookies.