public function testExecuteMigrationQueryDryRunEmptyDescription() { $queryDescription = null; $query = $this->getMock('Oro\\Bundle\\MigrationBundle\\Migration\\MigrationQuery'); $query->expects($this->once())->method('getDescription')->will($this->returnValue($queryDescription)); $this->logger->expects($this->never())->method('info'); $query->expects($this->never())->method('execute'); $this->executor->execute($query, true); }
/** * 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); } } }
/** * @param Schema $schema * @param AbstractPlatform $platform * @param Migration $migration * @param bool $dryRun * * @return bool */ public function executeUpMigration(Schema &$schema, AbstractPlatform $platform, Migration $migration, $dryRun = false) { $result = true; $this->logger->notice(sprintf('> %s', get_class($migration))); $toSchema = clone $schema; $this->setExtensions($migration); try { $queryBag = new QueryBag(); $migration->up($toSchema, $queryBag); $comparator = new Comparator(); $schemaDiff = $comparator->compare($schema, $toSchema); $this->checkTables($schemaDiff, $migration); $this->checkIndexes($schemaDiff, $migration); $queries = array_merge($queryBag->getPreQueries(), $schemaDiff->toSql($platform), $queryBag->getPostQueries()); $schema = $toSchema; foreach ($queries as $query) { $this->queryExecutor->execute($query, $dryRun); } } catch (\Exception $ex) { $result = false; $this->logger->error(sprintf(' ERROR: %s', $ex->getMessage())); } return $result; }