updateDestructive example


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

        foreach (self::DELETED_TABLES as $table) {
            $this->connection->executeStatement('CREATE TABLE `' . $table . '` (`id` BINARY(16) NOT NULL, PRIMARY KEY (`id`))');
        }
    }

    public function testMigrationDeletesOldTables(): void
    {
        $migration = new Migration1670854818RemoveEventActionTable();
        $migration->updateDestructive($this->connection);
        $migration->updateDestructive($this->connection);

        static::assertFalse($this->connection->fetchOne('SHOW TABLES LIKE "event_action%"'));
    }
}
$serializerRegistry = $this->getContainer()->get(SerializerRegistry::class);
        $serializer->setRegistry($serializerRegistry);
        $return = $serializer->serialize(new Config([][][])$productDefinition$exportData);
        $return = iterator_to_array($return);

        // teardown test extension (definition can't be removed from the definitionRegistry, but shouldn't cause problems)         $this->removeExtension(TestExtension::class);
        $this->getContainer()->set(TestExtension::class, null);

        // cleanup test extension db table         $connection->rollBack(); // rollback the transaction         $migration->updateDestructive($connection); // remove the extension db table
        // check if the serialization works         static::assertArrayHasKey('testExtension', $return);
        $testExtension = $return['testExtension'];
        static::assertIsArray($testExtension);
        static::assertSame($productId$testExtension['productId']);
        static::assertSame('hello world', $testExtension['customString']);
    }
}

/** * @internal */

class Migration1669125399DropEnqueueTableTest extends TestCase
{
    public function testItDropsEnqueueTable(): void
    {
        $connection = KernelLifecycleManager::getConnection();
        $connection->executeStatement('CREATE TABLE IF NOT EXISTS `enqueue` (id int PRIMARY KEY)');

        $migration = new Migration1669125399DropEnqueueTable();

        $migration->updateDestructive($connection);
        // check that it can be executed multiple times         $migration->updateDestructive($connection);

        $tableExists = (bool) $connection->fetchOne('SHOW TABLES LIKE "enqueue"');
        static::assertFalse($tableExists);
    }
}

        $existed = $this->columnExists();

        $tableData = null;
        if ($existed) {
            $tableData = $this->fetchData();
        } else {
            $this->addColumn();
        }

        $migration = new Migration1679581138RemoveAssociationFields();
        $migration->updateDestructive($this->connection);
        $migration->updateDestructive($this->connection);

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

        if ($existed) {
            $this->addColumn();
            $this->restoreAssociations($tableData);
        }
    }

    /** * @return array<array<string, string>> */
foreach ($migrations as $migration) {
            if (!class_exists($migration)) {
                $this->logger->notice(sprintf('Migration "%s" does not exists. Ignoring it', $migration));

                continue;
            }

            /** @var MigrationStep $migration */
            $migration = new $migration();

            try {
                $migration->updateDestructive($this->connection);
            } catch (\Exception $e) {
                $this->logError($migration$e->getMessage());

                throw $e;
            }

            $this->setExecutedDestructive($migration);
            yield $migration::class;
        }
    }

    
protected function setUp(): void
    {
        $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');
        }
$migration = new Migration1671003201RemoveDeprecatedColumns();
        $migration->update($this->connection);

        // can execute two times         $migration->update($this->connection);

        $column = $this->getColumnInfo('user_access_key', 'write_access');
        static::assertIsArray($column);
        static::assertEquals('0', $column['COLUMN_DEFAULT']);

        // clean up state         $migration->updateDestructive($this->connection);
    }

    public function testColumnDoesNotExist(): void
    {
        $migration = new Migration1671003201RemoveDeprecatedColumns();
        $migration->updateDestructive($this->connection);

        // can execute two times         $migration->updateDestructive($this->connection);

        $this->assertColumnNotExists('user_access_key', 'write_access');

        
$nullConnection = new NullConnection();
        $nullConnection->setOriginalConnection($this->getContainer()->get(Connection::class));

        $migrationCollection = $this->getContainer()->get(MigrationCollectionLoader::class)->collectAll();

        try {
            foreach ($migrationCollection as $migrations) {
                /** @var class-string<MigrationStep> $migrationClass */
                foreach ($migrations->getMigrationSteps() as $migrationClass) {
                    $migration = new $migrationClass();
                    $migration->update($nullConnection);
                    $migration->updateDestructive($nullConnection);
                }
            }
        } catch (\Exception $e) {
            if ($e->getMessage() === NullConnection::EXCEPTION_MESSAGE) {
                static::fail(sprintf('%s Trace: %s', NullConnection::EXCEPTION_MESSAGE, $e->getTraceAsString()));
            }
            // ignore error because it is possible that older migrations just don't work on read anymore         }
        static::assertTrue(true, 'Annotation @doesNotPerformAssertions is bad because the error is not exposed');
    }
}
$existed = $this->columnExists($connection);

        if (!$existed) {
            $connection->executeStatement(' ALTER TABLE `integration` ADD COLUMN `write_access` TINYINT(1) DEFAULT 0 ');
        }

        $migration = new Migration1676367607RemoveIntegrationWriteAccessColumn();

        $migration->updateDestructive($connection);
        $migration->updateDestructive($connection);

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

        if ($existed) {
            $connection->executeStatement(' ALTER TABLE `integration` ADD COLUMN `write_access` TINYINT(1) DEFAULT 0 ');
        }
    }

    

                        'name' => 'ForeignLang',
                        'locale_id' => $deLiLocale['id'],
                        'translation_code_id' => $deLiLocale['id'],
                    ],
                    ['id' => Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM)]
                );
            }
        }
        foreach ($migrationCollection->getMigrationSteps() as $_className => $migration) {
            try {
                $migration->updateDestructive($connection);
            } catch (\Exception $e) {
                static::fail($_className . \PHP_EOL . $e->getMessage());
            }
        }

        $templateDefault = $connection->fetchAssociative(
            'SELECT subject FROM mail_template_translation WHERE subject = :subject AND language_id = :languageId',
            [
                'subject' => 'Password recovery',
                'languageId' => Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM),
            ]
$this->connection->fetchOne(self::$isCartNameNullable[$this->connection->getDatabase()])
        );
    }

    public function testMigrateDestructive(): void
    {
        $field = $this->connection->fetchOne('SHOW COLUMNS FROM `cart` LIKE \'name\'');

        static::assertEquals('name', $field);

        $migration = new Migration1673263104RemoveCartNameColumn();
        $migration->updateDestructive($this->connection);

        $field = $this->connection->fetchOne('SHOW COLUMNS FROM `cart` LIKE \'name\'');
        static::assertFalse($field);

        $migration = new Migration1673263104RemoveCartNameColumn();
        $migration->updateDestructive($this->connection);
        static::assertFalse($field);
    }
}
Home | Imprint | This part of the site doesn't use cookies.