/** * Executes UP method for the given migrations * * @param MigrationState[] $migrations * @param bool $dryRun * * @throws \RuntimeException if at lease one migration failed */ public function executeUp(array $migrations, $dryRun = false) { $platform = $this->queryExecutor->getConnection()->getDatabasePlatform(); $sm = $this->queryExecutor->getConnection()->getSchemaManager(); $schema = $this->createSchemaObject($sm->listTables(), $platform->supportsSequences() ? $sm->listSequences() : [], $sm->createSchemaConfig()); $failedMigrations = false; foreach ($migrations as $item) { $migration = $item->getMigration(); if (!empty($failedMigrations) && !$migration instanceof FailIndependentMigration) { $this->logger->notice(sprintf('> %s - skipped', get_class($migration))); continue; } if ($this->executeUpMigration($schema, $platform, $migration, $dryRun)) { $item->setSuccessful(); } else { $item->setFailed(); $failedMigrations[] = get_class($migration); } } if (!empty($failedMigrations)) { throw new \RuntimeException(sprintf('Failed migrations: %s.', implode(', ', $failedMigrations))); } }
/** * Executes UP method for the given migrations * * @param Migration[] $migrations * @param bool $dryRun * @throws InvalidNameException if invalid table or column name is detected */ public function executeUp(array $migrations, $dryRun = false) { $platform = $this->queryExecutor->getConnection()->getDatabasePlatform(); $sm = $this->queryExecutor->getConnection()->getSchemaManager(); $fromSchema = $this->createSchemaObject($sm->listTables(), $platform->supportsSequences() ? $sm->listSequences() : [], $sm->createSchemaConfig()); $queryBag = new QueryBag(); foreach ($migrations as $migration) { $this->logger->notice(sprintf('> %s', get_class($migration))); $toSchema = clone $fromSchema; $this->setExtensions($migration); $migration->up($toSchema, $queryBag); $comparator = new Comparator(); $schemaDiff = $comparator->compare($fromSchema, $toSchema); $this->checkTables($schemaDiff, $migration); $this->checkIndexes($schemaDiff, $migration); $queries = array_merge($queryBag->getPreQueries(), $schemaDiff->toSql($platform), $queryBag->getPostQueries()); $fromSchema = $toSchema; $queryBag->clear(); foreach ($queries as $query) { $this->queryExecutor->execute($query, $dryRun); } } }
public function testGetConnection() { $this->assertSame($this->connection, $this->executor->getConnection()); }