columnExists example

public function getCreationTimestamp(): int
    {
        return 1648709176;
    }

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

    public function updateDestructive(Connection $connection): void
    {
        if (!$this->columnExists($connection, 'cart', 'compressed')) {
            $connection->executeStatement('ALTER TABLE `cart` ADD `compressed` tinyint(1) NOT NULL DEFAULT 0;');
        }

        // after adding the payload column, we may save carts as compressed serialized objects, there is no way of return at this point         if (!$this->columnExists($connection, 'cart', 'payload')) {
            $connection->executeStatement('ALTER TABLE `cart` ADD `payload` LONGBLOB NULL;');
        }

        if (!$this->columnExists($connection, 'cart', 'cart')) {
            return;
        }

        

#[Package('content')] class Migration1662533751AddCustomEntityTypeIdToCategory extends MigrationStep
{
    public function getCreationTimestamp(): int
    {
        return 1662533751;
    }

    public function update(Connection $connection): void
    {
        if (!$this->columnExists($connection, 'category', 'custom_entity_type_id')) {
            $connection->executeStatement(
                'ALTER TABLE `category` ADD `custom_entity_type_id` BINARY(16) NULL, ADD CONSTRAINT `fk.category.custom_entity_type_id` FOREIGN KEY (`custom_entity_type_id`) REFERENCES `custom_entity` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;'
            );
        }
    }

    public function updateDestructive(Connection $connection): void
    {
        // implement update destructive

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

    public function update(Connection $connection): void
    {
        if ($this->columnExists($connection, 'customer', 'created_by_id') || $this->columnExists($connection, 'customer', 'updated_by_id')) {
            return;
        }

        $connection->executeStatement(' ALTER TABLE `customer` ADD COLUMN `created_by_id` BINARY(16) NULL AFTER `bound_sales_channel_id`, ADD COLUMN `updated_by_id` BINARY(16) NULL AFTER `created_by_id`; ');

        $connection->executeStatement('ALTER TABLE `customer` ADD CONSTRAINT `fk.customer.created_by_id` FOREIGN KEY (`created_by_id`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE');

        
public function getCreationTimestamp(): int
    {
        return 1678969082;
    }

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

    public function updateDestructive(Connection $connection): void
    {
        if ($this->columnExists($connection, 'product', 'display_parent')) {
            $connection->executeStatement(
                'ALTER TABLE `product` DROP COLUMN `display_parent`'
            );
        }

        if ($this->columnExists($connection, 'product', 'configurator_group_config')) {
            $connection->executeStatement(
                'ALTER TABLE `product` DROP COLUMN `configurator_group_config`'
            );
        }

        

#[Package('content')] class Migration1659425718AddFlagsToCustomEntities extends MigrationStep
{
    public function getCreationTimestamp(): int
    {
        return 1659425718;
    }

    public function update(Connection $connection): void
    {
        if (!$this->columnExists($connection, 'custom_entity', 'flags')) {
            $connection->executeStatement('ALTER TABLE `custom_entity` ADD `flags` JSON NULL;');
        }
    }

    public function updateDestructive(Connection $connection): void
    {
        // implement update destructive     }
}
use KernelTestBehaviour;

    private const CUSTOM_FIELD_A = 'migration_test_foo';
    private const CUSTOM_FIELD_B = 'migration_test_bar';
    private const CUSTOM_FIELD_C = 'migration_test_baz';

    public function testColumnGetsCreatedAndExposeSetting(): void
    {
        /** @var Connection $con */
        $con = $this->getContainer()->get(Connection::class);

        if ($this->columnExists($con)) {
            $con->executeStatement('ALTER TABLE `custom_field` DROP `allow_cart_expose`;');
        }

        static::assertFalse($this->columnExists($con));

        $m = new Migration1681382023AddCustomFieldAllowCartExpose();
        $m->update($con);

        static::assertTrue($this->columnExists($con));

        $con->setNestTransactionsWithSavepoints(true);
        

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

    public function update(Connection $connection): void
    {
        if ($this->columnExists($connection, 'order', 'source')) {
            return;
        }

        $connection->executeStatement(' ALTER TABLE `order` ADD COLUMN `source` VARCHAR(255) NULL; ');
    }

    public function updateDestructive(Connection $connection): void
    {
    }
$this->connection->executeStatement(
            'UPDATE `cart` SET `token` = :newToken WHERE `token` = :oldToken',
            ['newToken' => $newToken, 'oldToken' => $oldToken]
        );
    }

    /** * @deprecated tag:v6.6.0 - will be removed */
    private function payloadExists(): bool
    {
        return EntityDefinitionQueryHelper::columnExists($this->connection, 'cart', 'payload');
    }

    private function serializeCart(Cart $cart, bool $payloadExists): string
    {
        $errors = $cart->getErrors();
        $data = $cart->getData();

        $cart->setErrors(new ErrorCollection());
        $cart->setData(null);

        $this->cartSerializationCleaner->cleanupCart($cart);

        
$this->connection = KernelLifecycleManager::getConnection();
        $this->migration = new Migration1678969082DropVariantListingFields();

        $this->rollbackMigration();
    }

    public function testMigration(): void
    {
        $this->migration->updateDestructive($this->connection);
        $this->migration->updateDestructive($this->connection);

        static::assertFalse(EntityDefinitionQueryHelper::columnExists($this->connection, 'product', 'configurator_group_config'));
        static::assertFalse(EntityDefinitionQueryHelper::columnExists($this->connection, 'product', 'display_parent'));
        static::assertFalse(EntityDefinitionQueryHelper::columnExists($this->connection, 'product', 'main_variant_id'));
    }

    private function rollbackMigration(): void
    {
        if (EntityDefinitionQueryHelper::columnExists($this->connection, 'product', 'variant_listing_config')) {
            $this->connection->executeStatement('ALTER TABLE `product` DROP COLUMN `variant_listing_config`, ADD COLUMN `variant_listing_config` JSON NULL DEFAULT NULL');
        }

        if (!EntityDefinitionQueryHelper::columnExists($this->connection, 'product', 'display_parent')) {
            
private function createCart(string $contextToken): void
    {
        $connection = $this->getContainer()->get(Connection::class);

        $defaultCountry = $connection->fetchOne('SELECT id FROM country WHERE active = 1 ORDER BY `position`');
        $defaultPaymentMethod = $connection->fetchOne('SELECT id FROM payment_method WHERE active = 1 ORDER BY `position`');
        $defaultShippingMethod = $connection->fetchOne('SELECT id FROM shipping_method WHERE active = 1');

        // @deprecated tag:v6.6.0 - keep $column = 'payload'         $column = 'cart';
        if (EntityDefinitionQueryHelper::columnExists($connection, 'cart', 'payload')) {
            $column = 'payload';
        }

        $connection->insert('cart', [
            'token' => $contextToken,
            $column => serialize(new Cart($contextToken)),
            'line_item_count' => 1,
            'rule_ids' => json_encode([]),
            'currency_id' => Uuid::fromHexToBytes(Defaults::CURRENCY),
            'country_id' => $defaultCountry,
            'price' => 1,
            

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

    public function update(Connection $connection): void
    {
        if ($this->columnExists($connection, 'product_export', 'is_running')) {
            return;
        }

        $sql = <<<'SQL' ALTER TABLE `product_export` ADD COLUMN `is_running` TINYINT(1) NOT NULL DEFAULT 0 SQL;

        $connection->executeStatement($sql);
    }

    
class Migration1676272000AddAccountTypeToCustomer extends MigrationStep
{
    private const CHUNK_SIZE = 5000;

    public function getCreationTimestamp(): int
    {
        return 1676272000;
    }

    public function update(Connection $connection): void
    {
        $isAdded = $this->columnExists($connection, 'customer', 'account_type');
        if (!$isAdded) {
            $connection->executeStatement(' ALTER TABLE `customer` ADD COLUMN `account_type` VARCHAR(255) NOT NULL DEFAULT \'private\' AFTER `bound_sales_channel_id` ');
        }

        $this->massUpdateAccountType($connection);
    }

    public function updateDestructive(Connection $connection): void
    {

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

    public function update(Connection $connection): void
    {
        if (!$this->columnExists($connection, 'custom_entity', 'custom_fields_aware')) {
            $connection->executeStatement('ALTER TABLE `custom_entity` ADD `custom_fields_aware` TINYINT(1) DEFAULT 0;');
            $connection->executeStatement('ALTER TABLE `custom_entity` ADD `label_property` VARCHAR(255) NULL;');
        }
    }

    public function updateDestructive(Connection $connection): void
    {
        // implement update destructive     }
}

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

    public function update(Connection $connection): void
    {
        if (!EntityDefinitionQueryHelper::columnExists($connection, 'product', 'states')) {
            $connection->executeStatement(' ALTER TABLE `product` ADD COLUMN `states` JSON NULL, ADD CONSTRAINT `json.product.states` CHECK (JSON_VALID(`states`)) ');
            $connection->executeStatement(' UPDATE `product` SET `states` = :states WHERE `states` IS NULL ', ['states' => json_encode([State::IS_PHYSICAL])]);
        }

        
public function getCreationTimestamp(): int
    {
        return 1675082889;
    }

    public function update(Connection $connection): void
    {
        $connection->executeStatement('DROP TABLE IF EXISTS `message_queue_stats`');
        $connection->executeStatement('DROP TABLE IF EXISTS `mail_template_sales_channel`');
        $connection->executeStatement('DROP TABLE IF EXISTS `sales_channel_rule`');

        if (EntityDefinitionQueryHelper::columnExists($connection, 'customer_address', 'vat_id')) {
            $connection->executeStatement('ALTER TABLE `customer_address` DROP COLUMN `vat_id`');
        }

        if (EntityDefinitionQueryHelper::columnExists($connection, 'customer', 'newsletter')) {
            $connection->executeStatement('ALTER TABLE `customer` DROP COLUMN `newsletter`');
        }

        if (EntityDefinitionQueryHelper::columnExists($connection, 'product', 'whitelist_ids')) {
            $connection->executeStatement('ALTER TABLE `product` DROP COLUMN `whitelist_ids`');
        }

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