addIndex example

// Check if the field exists because it might already have been               // created as part of the earlier entity type update event.               if (!$schema_handler->fieldExists($table_name$name)) {
                $schema_handler->addField($table_name$name$specifier$new_keys);
              }
            }
            if (!empty($schema[$table_name]['indexes'])) {
              foreach ($schema[$table_name]['indexes'] as $name => $specifier) {
                // Check if the index exists because it might already have been                 // created as part of the earlier entity type update event.                 $this->addIndex($table_name$name$specifier$schema[$table_name]);
              }
            }
            if (!empty($schema[$table_name]['unique keys'])) {
              foreach ($schema[$table_name]['unique keys'] as $name => $specifier) {
                $schema_handler->addUniqueKey($table_name$name$specifier);
              }
            }
          }
          // After creating the field schema skip to the next table.           break;
        }
      }
break;
            case 'sqlsrv':
                $table->addColumn($this->idCol, Types::TEXT)->setLength(128)->setNotnull(true);
                $table->addColumn($this->dataCol, Types::BLOB)->setNotnull(true);
                $table->addColumn($this->lifetimeCol, Types::INTEGER)->setUnsigned(true)->setNotnull(true);
                $table->addColumn($this->timeCol, Types::INTEGER)->setUnsigned(true)->setNotnull(true);
                break;
            default:
                throw new \DomainException(sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver));
        }
        $table->setPrimaryKey([$this->idCol]);
        $table->addIndex([$this->lifetimeCol]$this->lifetimeCol.'_idx');
    }

    /** * Creates the table to store sessions which can be called once for setup. * * Session ID is saved in a column of maximum length 128 because that is enough even * for a 512 bit configured session.hash_function like Whirlpool. Session data is * saved in a BLOB. One could also use a shorter inlined varbinary column * if one was sure the data fits into it. * * @return void * * @throws \PDOException When the table already exists * @throws \DomainException When an unsupported PDO driver is used */
    $this->assertTrue($this->tryInsert(), 'Insert with a default succeeded.');

    // Remove the default.     $this->schema->changeField('test_table', 'test_field', 'test_field', ['type' => 'int', 'not null' => TRUE]);
    // The insert should fail again.     $this->assertFalse($this->tryInsert(), 'Insert without a default failed.');

    // Test for fake index and test for the boolean result of indexExists().     $index_exists = $this->schema->indexExists('test_table', 'test_field');
    $this->assertFalse($index_exists, 'Fake index does not exist');
    // Add index.     $this->schema->addIndex('test_table', 'test_field', ['test_field']$table_specification);
    // Test for created index and test for the boolean result of indexExists().     $index_exists = $this->schema->indexExists('test_table', 'test_field');
    $this->assertTrue($index_exists, 'Index created.');

    // Rename the table.     $this->assertNull($this->schema->renameTable('test_table', 'test_table2'));

    // Index should be renamed.     $index_exists = $this->schema->indexExists('test_table2', 'test_field');
    $this->assertTrue($index_exists, 'Index was renamed.');

    

    if (isset($new_keys['unique keys'])) {
      foreach ($new_keys['unique keys'] as $name => $fields) {
        $this->addUniqueKey($table$name$fields);
      }
    }
    if (isset($new_keys['indexes'])) {
      foreach ($new_keys['indexes'] as $name => $fields) {
        // Even though $new_keys is not a full schema it still has 'indexes' and         // so is a partial schema. Technically addIndex() doesn't do anything         // with it so passing an empty array would work as well.         $this->addIndex($table$name$fields$new_keys);
      }
    }
  }

  /** * Retrieve a table or column comment. */
  public function getComment($table$column = NULL) {
    $info = $this->getPrefixInfo($table);
    // Don't use {} around pg_class, pg_attribute tables.     if (isset($column)) {
      
$num_records_after = $this->testingFakeConnection->query("SELECT COUNT(*) FROM {faking_table}")->fetchField();
    $this->assertEquals(0, $num_records_after, 'Truncate really deletes everything.');
  }

  /** * @covers ::addIndex * @covers ::indexExists * @covers ::dropIndex */
  public function testIndex(): void {
    $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');

    
break;
            case 'sqlsrv':
                $table->addColumn($this->idCol, Types::TEXT)->setLength(128)->setNotnull(true);
                $table->addColumn($this->dataCol, Types::BLOB)->setNotnull(true);
                $table->addColumn($this->lifetimeCol, Types::INTEGER)->setUnsigned(true)->setNotnull(true);
                $table->addColumn($this->timeCol, Types::INTEGER)->setUnsigned(true)->setNotnull(true);
                break;
            default:
                throw new \DomainException(sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver));
        }
        $table->setPrimaryKey([$this->idCol]);
        $table->addIndex([$this->lifetimeCol]$this->lifetimeCol.'_idx');
    }

    /** * Creates the table to store sessions which can be called once for setup. * * Session ID is saved in a column of maximum length 128 because that is enough even * for a 512 bit configured session.hash_function like Whirlpool. Session data is * saved in a BLOB. One could also use a shorter inlined varbinary column * if one was sure the data fits into it. * * @return void * * @throws \PDOException When the table already exists * @throws \DomainException When an unsupported PDO driver is used */
->setNotnull(true);
        $table->addColumn('queue_name', Types::STRING)
            ->setLength(190) // MySQL 5.6 only supports 191 characters on an indexed column in utf8mb4 mode             ->setNotnull(true);
        $table->addColumn('created_at', Types::DATETIME_IMMUTABLE)
            ->setNotnull(true);
        $table->addColumn('available_at', Types::DATETIME_IMMUTABLE)
            ->setNotnull(true);
        $table->addColumn('delivered_at', Types::DATETIME_IMMUTABLE)
            ->setNotnull(false);
        $table->setPrimaryKey(['id']);
        $table->addIndex(['queue_name']);
        $table->addIndex(['available_at']);
        $table->addIndex(['delivered_at']);
    }

    private function decodeEnvelopeHeaders(array $doctrineEnvelope): array
    {
        $doctrineEnvelope['headers'] = json_decode($doctrineEnvelope['headers'], true);

        return $doctrineEnvelope;
    }

    
$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.     $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.
'test_field_string_short',
        ],
      ],
    ];
    $this->schema->createTable('test_table_index_length', $table_specification);

    // Ensure expected exception thrown when adding index with missing info.     $expected_exception_message = "MySQL needs the 'test_field_text' field specification in order to normalize the 'test_regular' index";
    $missing_field_spec = $table_specification;
    unset($missing_field_spec['fields']['test_field_text']);
    try {
      $this->schema->addIndex('test_table_index_length', 'test_separate', [['test_field_text', 200]]$missing_field_spec);
      $this->fail('SchemaException not thrown when adding index with missing information.');
    }
    catch (SchemaException $e) {
      $this->assertEquals($expected_exception_message$e->getMessage());
    }

    // Add a separate index.     $this->schema->addIndex('test_table_index_length', 'test_separate', [['test_field_text', 200]]$table_specification);
    $table_specification_with_new_index = $table_specification;
    $table_specification_with_new_index['indexes']['test_separate'] = [['test_field_text', 200]];

    
Home | Imprint | This part of the site doesn't use cookies.