dropIndex example

$this->testingFakeConnection->schema()->addIndex('faking_table', 'test_field', ['test_field'][]);

    $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__idx'])->fetchAll();

    $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()->dropIndex('faking_table', 'test_field');

    $this->assertFalse($this->testingFakeConnection->schema()->indexExists('faking_table', 'test_field'));
  }

  /** * @covers ::addUniqueKey * @covers ::indexExists * @covers ::dropUniqueKey */
  public function testUniqueKey(): void {
    $this->testingFakeConnection->schema()->addUniqueKey('faking_table', 'test_field', ['test_field']);

    
// SQLite doesn't allow you to rename tables outside of the current     // database. So the syntax '... RENAME TO database.table' would fail.     // So we must determine the full table name here rather than surrounding     // the table with curly braces in case the db_prefix contains a reference     // to a database outside of our existing database.     $info = $this->getPrefixInfo($new_name);
    $this->connection->query('ALTER TABLE {' . $table . '} RENAME TO [' . $info['table'] . ']');

    // Drop the indexes, there is no RENAME INDEX command in SQLite.     if (!empty($schema['unique keys'])) {
      foreach ($schema['unique keys'] as $key => $fields) {
        $this->dropIndex($table$key);
      }
    }
    if (!empty($schema['indexes'])) {
      foreach ($schema['indexes'] as $index => $fields) {
        $this->dropIndex($table$index);
      }
    }

    // Recreate the indexes.     $statements = $this->createIndexSql($new_name$schema);
    foreach ($statements as $statement) {
      
$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.     $this->assertEquals(['update']$introspect_index_schema->invoke($this->schema, $table_name_new)['indexes'][$index_introspect_name]);

    // Dropping an index.     $this->schema->dropIndex($table_name_new$index_name);
    $this->assertFalse($this->schema->indexExists($table_name_new$index_name));

    // Dropping a table.     $this->schema->dropTable($table_name_new);
    $this->assertFalse($this->schema->tableExists($table_name_new));
  }

  /** * Tests changing a field length. */
  public function testChangeSerialFieldLength(): void {
    
// Iterate over the mapped table to find the ones that host the deleted     // field schema.     foreach ($shared_table_names as $table_name) {
      foreach ($table_mapping->getFieldNames($table_name) as $field_name) {
        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);
          }
          
// 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.     $index_introspect_name = $ensure_identifiers_length->invoke($this->schema, $table_name_new$index_name, 'idx');
    $this->assertEquals(['update']$introspect_index_schema->invoke($this->schema, $table_name_new)['indexes'][$index_introspect_name]);

    // Dropping an index.     $this->schema->dropIndex($table_name_new$index_name);
    $this->assertFalse($this->schema->indexExists($table_name_new$index_name));

    // Dropping a table.     $this->schema->dropTable($table_name_new);
    $this->assertFalse($this->schema->tableExists($table_name_new));
  }

  /** * @covers \Drupal\Core\Database\Driver\pgsql\Schema::extensionExists */
  public function testPgsqlExtensionExists(): void {
    
Home | Imprint | This part of the site doesn't use cookies.