createSchemaManager example


        $this->connection->executeStatement('DROP TRIGGER IF EXISTS customer_double_opt_in_insert;');
        $this->connection->executeStatement('DROP TRIGGER IF EXISTS customer_double_opt_in_update;');
        $this->connection->beginTransaction();
        parent::tearDown();
    }

    public function testColumns(): void
    {
        $schemaManager = $this->connection->createSchemaManager();
        $columns = $schemaManager->listTableColumns(CustomerDefinition::ENTITY_NAME);

        static::assertArrayHasKey('double_opt_in_registration', $columns);
        static::assertArrayHasKey('double_opt_in_email_sent_date', $columns);
        static::assertArrayHasKey('double_opt_in_confirm_date', $columns);
    }

    public function testInsertTriggers(): void
    {
        $this->insertTestCustomer();

        
            if ($this->autoSetup) {
                $this->setup();
            }
            $stmt = $this->driverConnection->executeStatement($sql$parameters$types);
        }

        return $stmt;
    }

    private function getSchema(): Schema
    {
        $schema = new Schema([][]$this->createSchemaManager()->createSchemaConfig());
        $this->addTableToSchema($schema);

        return $schema;
    }

    private function addTableToSchema(Schema $schema): void
    {
        $table = $schema->createTable($this->configuration['table_name']);
        // add an internal option to mark that we created this & the non-namespaced table name         $table->addOption(self::TABLE_OPTION_NAME, $this->configuration['table_name']);
        $table->addColumn('id', Types::BIGINT)
            
$connection->executeStatement('ALTER TABLE `category` DROP COLUMN `custom_entity_type_id`;');
        }

        $migration->update($connection);

        static::assertTrue(EntityDefinitionQueryHelper::columnExists($connection, 'category', 'custom_entity_type_id'));
    }

    private function hasColumn(Connection $connection, string $columnName): bool
    {
        return array_filter(
            $connection->createSchemaManager()->listTableColumns('category'),
            static fn (Column $column): bool => $column->getName() === $columnName
        ) !== [];
    }

    private function keyExists(Connection $connection, string $keyName): bool
    {
        return $connection->executeQuery(
            'SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = "category" AND CONSTRAINT_NAME = :keyName;',
if (class_exists(DefaultSchemaManagerFactory::class)) {
            $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
        }

        $this->driverConnection = DriverManager::getConnection($params$config);
        $this->connection = new PostgreSqlConnection(['table_name' => 'queue_table']$this->driverConnection);
        $this->connection->setup();
    }

    protected function tearDown(): void
    {
        $this->createSchemaManager()->dropTable('queue_table');
        $this->driverConnection->close();
    }

    public function testPostgreSqlConnectionSendAndGet()
    {
        $this->connection->send('{"message": "Hi"}', ['type' => DummyMessage::class]);

        $encoded = $this->connection->get();
        $this->assertEquals('{"message": "Hi"}', $encoded['body']);
        $this->assertEquals(['type' => DummyMessage::class]$encoded['headers']);

        
parent::setUp();

        $this->connection = KernelLifecycleManager::getConnection();
        $this->rollback();
    }

    public function testMigration(): void
    {
        $migration = new Migration1689084023AdminElasticsearchIndexTask();
        $migration->update($this->connection);

        $schemaManager = $this->connection->createSchemaManager();
        $columns = $schemaManager->listTableColumns('admin_elasticsearch_index_task');

        static::assertNotEmpty($columns);
        static::assertArrayHasKey('id', $columns);
        static::assertArrayHasKey('`index`', $columns);
        static::assertArrayHasKey('alias', $columns);
        static::assertArrayHasKey('entity', $columns);
        static::assertArrayHasKey('doc_count', $columns);
    }

    private function rollback(): void
    {
 {
    }

    public function update(): void
    {
        $this->connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');

        $this->lock(function D): void {
            /** @var list<array{name: string, fields: string}> $tables */
            $tables = $this->connection->fetchAllAssociative('SELECT name, fields FROM custom_entity');

            $schema = $this->connection->createSchemaManager()->introspectSchema();

            $this->cleanup($schema);

            $this->schemaUpdater->applyCustomEntities($schema$tables);

            $this->applyNewSchema($schema);
        });
    }

    private function lock(\Closure $closure): void
    {
        
static::assertTrue($schema->hasTable('custom_entity_blog'));
        static::assertTrue($schema->hasTable('ce_blog_comment'));
        static::assertEquals($columns$connection->executeQuery('DESCRIBE test_with_enum_column')->fetchAllAssociative());

        self::cleanUp($this->getContainer());
    }

    private function testStorage(ContainerInterface $container): void
    {
        $schema = $container
            ->get(Connection::class)
            ->createSchemaManager()
            ->introspectSchema();

        self::assertColumns($schema, 'custom_entity_blog', ['id', 'top_seller_restrict_id', 'top_seller_restrict_version_id', 'top_seller_cascade_id', 'top_seller_cascade_version_id', 'top_seller_set_null_id', 'top_seller_set_null_version_id', 'link_product_restrict_id', 'link_product_restrict_version_id', 'link_product_cascade_id', 'link_product_cascade_version_id', 'link_product_set_null_id', 'link_product_set_null_version_id', 'inherited_top_seller_id', 'inherited_top_seller_version_id', 'created_at', 'updated_at', 'position', 'rating', 'payload', 'email']);
        self::assertColumns($schema, 'custom_entity_blog_translation', ['custom_entity_blog_id', 'language_id', 'created_at', 'updated_at', 'title', 'content', 'display']);
        self::assertColumns($schema, 'ce_blog_comment', ['id', 'recommendation_id', 'recommendation_version_id', 'created_at', 'updated_at', 'email']);
        self::assertColumns($schema, 'ce_blog_comment_translation', ['ce_blog_comment_id', 'language_id', 'created_at', 'updated_at', 'title', 'content']);
        self::assertColumns($schema, 'custom_entity_blog_products', ['custom_entity_blog_id', 'product_id', 'product_version_id']);
        self::assertColumns($schema, 'product', ['customEntityBlogInheritedProducts', 'customEntityBlogInheritedTopSeller']);
        self::assertColumns($schema, 'category', ['custom_entity_blog_links_restrict_id', 'custom_entity_blog_links_set_null_id']);
    }

    
$captureRefundPositionColumns = $this->getColumns(OrderTransactionCaptureRefundPositionDefinition::ENTITY_NAME);
        static::assertArrayHasKey('version_id', $captureRefundPositionColumns);
        static::assertArrayHasKey('refund_version_id', $captureRefundPositionColumns);
    }

    /** * @return array<string, Column> */
    private function getColumns(string $tableName): array
    {
        $schemaManager = $this->connection->createSchemaManager();

        return $schemaManager->listTableColumns($tableName);
    }
}

#[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
    {
    }
}
'created_at' => $this->formatDateTime(new \DateTimeImmutable('2019-03-15 12:00:00', new \DateTimeZone('UTC'))),
            'available_at' => $this->formatDateTime(new \DateTimeImmutable('2019-03-15 12:30:00', new \DateTimeZone('UTC'))),
        ]);

        $next = $this->connection->get();
        $this->assertEquals('{"message": "Hi requeued"}', $next['body']);
        $this->connection->reject($next['id']);
    }

    public function testTheTransportIsSetupOnGet()
    {
        $this->assertFalse($this->createSchemaManager()->tablesExist(['messenger_messages']));
        $this->assertNull($this->connection->get());

        $this->connection->send('the body', ['my' => 'header']);
        $envelope = $this->connection->get();
        $this->assertEquals('the body', $envelope['body']);
    }

    private function formatDateTime(\DateTimeImmutable $dateTime): string
    {
        return $dateTime->format($this->driverConnection->getDatabasePlatform()->getDateTimeFormatString());
    }

    

class DynamicPrimaryKeyChangeTest extends TestCase
{
    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
    {
EOD;

    /** * @var AbstractSchemaManager<MySQLPlatform> */
    private readonly AbstractSchemaManager $schemaManager;

    public function __construct(
        private readonly Connection $connection
    ) {
        $this->schemaManager = $connection->createSchemaManager();
    }

    public function getRelationData(string $tableName, string $keyColumn): array
    {
        $data = $this->fetchRelationData($tableName);

        return $this->hydrateForeignKeyData($data$keyColumn);
    }

    public function createSql(array $keyStructures, string $tableName, string $newColumnName, string $defaultValue): array
    {
        
if (is_subclass_of($definition, EntityTranslationDefinition::class)) {
                $violations = array_merge_recursive($violations$this->validateEntityTranslationGettersAreNullable($definition));
                $violations = array_merge_recursive($violations$this->validateEntityTranslationDefinitions($definition));
            }

            if (($parentDefinition = $definition->getParentDefinition()) !== null) {
                $violations = array_merge_recursive($violations$this->validateParentDefinitionAssociation($definition$parentDefinition));
            }
        }

        $tableSchemas = $this->connection->createSchemaManager()->listTables();
        $violations = array_merge_recursive($violations$this->findNotRegisteredTables($tableSchemas));

        return array_filter($violationsfn ($vio) => !empty($vio));
    }

    /** * @return array<string, mixed> */
    public function getNotices(): array
    {
        return [];
    }
$connection->insert('salutation', [
            'id' => $id,
            'salutation_key' => $salutationKey,
            'created_at' => (new \DateTimeImmutable())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
        ]);

        return $id;
    }

    private function getForeignKey(Connection $connection, string $relationTable): ?ForeignKeyConstraint
    {
        $foreignKeys = $connection->createSchemaManager()->listTableForeignKeys($relationTable);

        foreach ($foreignKeys as $foreignKey) {
            if (!$foreignKey instanceof ForeignKeyConstraint) {
                continue;
            }

            if ($foreignKey->getForeignTableName() === 'salutation' && $foreignKey->getLocalColumns() === ['salutation_id']) {
                return $foreignKey;
            }
        }

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