hasColumn example

protected function setUp(): void
    {
        parent::setUp();
        $this->connection = $this->getContainer()->get(Connection::class);
        $this->ids = new IdsCollection();
    }

    public function testMigrationColumn(): void
    {
        $this->removeColumn();
        static::assertFalse($this->hasColumn('order_line_item', 'promotion_id'));

        $migration = new Migration1648031611AddOrderLineItemPromotionId();
        $migration->update($this->connection);
        $migration->update($this->connection);

        static::assertTrue($this->hasColumn('order_line_item', 'promotion_id'));
    }

    /** * @dataProvider dataProviderPromotion */
    
->update($entities->toStorage());

        $this->getContainer()
            ->get(CustomEntitySchemaUpdater::class)
            ->update();

        $schema = $this->getSchema();

        self::assertColumns($schema, 'custom_entity_blog', ['id', 'created_at', 'updated_at', 'rating', 'payload', 'email']);
        self::assertColumns($schema, 'ce_blog_comment', ['id', 'created_at', 'updated_at', 'email']);

        static::assertFalse($schema->getTable('product')->hasColumn('ce_blog_comment_products_reverse_id'));
        static::assertFalse($schema->getTable('product')->hasColumn('custom_entity_to_remove_products_reverse_id'));

        static::assertFalse($schema->hasTable('custom_entity_blog_product'));
        static::assertFalse($schema->hasTable('custom_entity_to_remove'));

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

    public function testAllowDisableIsTrueIfNoRestrictDeleteIsUsed(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/_fixtures/without-restrict-delete');

        
'language_id' => Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM),
            'default_billing_address_id' => Uuid::fromHexToBytes($billingAddressId),
            'default_shipping_address_id' => Uuid::randomBytes(),
        ]$customerOverrides);

        $this->connection->insert('customer', $customer);
        $this->connection->insert('customer_address', $customerAddress);
    }

    private function dropAccountType(): void
    {
        if ($this->hasColumn('customer', 'account_type')) {
            $this->connection->executeStatement('ALTER TABLE `customer` DROP COLUMN `account_type`');
        }
    }

    /** * @return false|CustomerData */
    private function fetchCustomer(): false|array
    {
        /** @var false|CustomerData $results */
        $results = $this->connection->fetchAssociative(
            
private function addColumns(Schema $schema, Table $table, array $fields): void
    {
        $name = $table->getName();
        $binary = ['length' => 16, 'fixed' => true];

        $onDelete = [
            'set-null' => ['onUpdate' => 'cascade', 'onDelete' => 'set null'],
            'cascade' => ['onUpdate' => 'cascade', 'onDelete' => 'cascade'],
            'restrict' => ['onUpdate' => 'cascade', 'onDelete' => 'restrict'],
        ];

        if (!$table->hasColumn('created_at')) {
            $table->addColumn('created_at', Types::DATETIME_MUTABLE, ['notnull' => true]);
        }

        if (!$table->hasColumn('updated_at')) {
            $table->addColumn('updated_at', Types::DATETIME_MUTABLE, ['notnull' => false]);
        }

        foreach ($fields as $field) {
            $required = $field['required'] ?? false;

            $nullable = $required ? [] : ['notnull' => false, 'default' => null];

            
public function testColumnGetsCreated(): void
    {
        $connection = KernelLifecycleManager::getConnection();
        $migration = new Migration1662533751AddCustomEntityTypeIdToCategory();

        $keyExists = $this->keyExists($connection, 'fk.category.custom_entity_type_id');
        if ($keyExists) {
            $connection->executeStatement('ALTER TABLE `category` DROP FOREIGN KEY `fk.category.custom_entity_type_id`;');
        }

        $columnExists = $this->hasColumn($connection, 'custom_entity_type_id');
        if ($columnExists) {
            $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
    {
        
Home | Imprint | This part of the site doesn't use cookies.