listTableIndexes example

$this->createAddKeysPlaybookEntries($keyStructures$newColumnName$tableName),
            $this->createAddColumnsAndKeysPlaybookEntries($newColumnName$keyStructures$defaultValue)
        ));
    }

    private function createDropKeysPlaybookEntries(array $keyStructures): array
    {
        $playbook = [];
        foreach ($keyStructures as $constraintName => $keyStructure) {
            \assert(\is_string($keyStructure['TABLE_NAME']));

            $indexes = $this->schemaManager->listTableIndexes($keyStructure['TABLE_NAME']);

            $playbook[] = sprintf(self::DROP_FOREIGN_KEY, $keyStructure['TABLE_NAME']$constraintName);

            if (\array_key_exists(strtolower($constraintName)$indexes)) {
                $playbook[] = sprintf(self::DROP_KEY, $keyStructure['TABLE_NAME']$constraintName);
            }
        }

        return $playbook;
    }

    

#[Package('core')] class Migration1656928097AddNewsletterRecipientEmailIndex extends MigrationStep
{
    public function getCreationTimestamp(): int
    {
        return 1656928097;
    }

    public function update(Connection $connection): void
    {
        $existingIndexes = $connection->createSchemaManager()->listTableIndexes('newsletter_recipient');
        if (isset($existingIndexes['idx.newsletter_recipient.email'])) {
            return;
        }

        $connection->executeStatement('CREATE INDEX `idx.newsletter_recipient.email` ON `newsletter_recipient` (`email`)');
    }

    public function updateDestructive(Connection $connection): void
    {
    }
}

    use KernelTestBehaviour;

    public function testPrimaryKeyExistsEverywhere(): void
    {
        $connection = $this->getContainer()->get(Connection::class);
        $schemaManager = $connection->createSchemaManager();

        $tables = $schemaManager->listTableNames();

        foreach ($tables as $tableName) {
            $indexes = $schemaManager->listTableIndexes($tableName);

            static::assertArrayHasKey('primary', $indexes);
        }
    }

    public function testFullConversionAgainstFixtures(): void
    {
        $connection = $this->getContainer()->get(Connection::class);

        $this->importFixtureSchema();
        $schemaManager = $connection->createSchemaManager();

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