migrateInSteps example

public function migrateInSteps(?int $until = null, ?int $limit = null): \Generator
    {
        return $this->migrationRuntime->migrate($this->migrationSource, $until$limit);
    }

    /** * @return list<class-string<MigrationStep>> */
    public function migrateInPlace(?int $until = null, ?int $limit = null): array
    {
        return iterator_to_array($this->migrateInSteps($until$limit));
    }

    public function migrateDestructiveInSteps(?int $until = null, ?int $limit = null): \Generator
    {
        return $this->migrationRuntime->migrateDestructive($this->migrationSource, $until$limit);
    }

    /** * @return list<class-string<MigrationStep>> */
    public function migrateDestructiveInPlace(?int $until = null, ?int $limit = null): array
    {

        $this->connection->executeStatement(
            'DELETE FROM `migration` WHERE `class` LIKE \'%_test_migrations_valid_run_time%\' OR `class` LIKE \'%_test_migrations_valid_run_time_exceptions%\''
        );
    }

    public function testMigrationExecutionInGenerall(): void
    {
        $cnt = 0;
        $generator = $this->validMigrationCollection->migrateInSteps();

        while ($generator->valid()) {
            $generator->next();
            ++$cnt;
        }

        static::assertSame(2, $cnt);
    }

    public function testItWorksWithASingleMigration(): void
    {
        
$this->adapter->initializeShopwareDb($connection);

            $coreMigrations->sync();
        }

        // use 7 s as max execution time, so the UI stays responsive         $maxExecutionTime = min(\ini_get('max_execution_time'), 7);
        $startTime = microtime(true);
        $executedMigrations = $offset;

        $stopped = false;
        while (iterator_count($coreMigrations->migrateInSteps(null, 1)) === 1) {
            $runningSince = microtime(true) - $startTime;
            ++$executedMigrations;

            // if there are more than 5 seconds execution time left, we execute more migrations in this request, otherwise we return the result             // on first request only execute one migration, otherwise the UI will feel unresponsive             if ($runningSince + 5 > $maxExecutionTime || $executedMigrations === 1) {
                $stopped = true;

                break;
            }
        }

        
private readonly TagAwareAdapterInterface $cache,
        string $shopwareVersion
    ) {
        parent::__construct();

        $this->loader = $loader;
        $this->shopwareVersion = $shopwareVersion;
    }

    protected function getMigrationGenerator(MigrationCollection $collection, ?int $until, ?int $limit): \Generator
    {
        yield from $collection->migrateInSteps($until$limit);
    }

    protected function getMigrationsCount(MigrationCollection $collection, ?int $until, ?int $limit): int
    {
        return \count($collection->getExecutableMigrations($until$limit));
    }

    protected function configure(): void
    {
        $this
            ->addArgument('identifier', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'identifier to determine which migrations to run', ['core'])
            
Home | Imprint | This part of the site doesn't use cookies.