Exemple #1
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $isDbalOld = DbalVersion::compare('2.2.0') > 0;
     $configuration = $this->getMigrationConfiguration($input, $output);
     $conn = $configuration->getConnection();
     $platform = $conn->getDatabasePlatform();
     if ($filterExpr = $input->getOption('filter-expression')) {
         if ($isDbalOld) {
             throw new \InvalidArgumentException('The "--filter-expression" option can only be used as of Doctrine DBAL 2.2');
         }
         $conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpr);
     }
     $fromSchema = $conn->getSchemaManager()->createSchema();
     $toSchema = $this->getSchemaProvider()->createSchema();
     //Not using value from options, because filters can be set from config.yml
     if (!$isDbalOld && ($filterExpr = $conn->getConfiguration()->getFilterSchemaAssetsExpression())) {
         foreach ($toSchema->getTables() as $table) {
             $tableName = $table->getName();
             if (!preg_match($filterExpr, $this->resolveTableName($tableName))) {
                 $toSchema->dropTable($tableName);
             }
         }
     }
     $up = $this->buildCodeFromSql($configuration, $fromSchema->getMigrateToSql($toSchema, $platform));
     $down = $this->buildCodeFromSql($configuration, $fromSchema->getMigrateFromSql($toSchema, $platform));
     if (!$up && !$down) {
         $output->writeln('No changes detected in your mapping information.', 'ERROR');
         return;
     }
     $version = date('YmdHis');
     $path = $this->generateMigration($configuration, $input, $version, $up, $down);
     $output->writeln(sprintf('Generated new migration class to "<info>%s</info>" from schema differences.', $path));
 }
 /**
  * @param string $tableName
  */
 public function __construct(Connection $connection, SerializerInterface $payloadSerializer, SerializerInterface $metadataSerializer, $tableName, $useBinary = false)
 {
     $this->connection = $connection;
     $this->payloadSerializer = $payloadSerializer;
     $this->metadataSerializer = $metadataSerializer;
     $this->tableName = $tableName;
     $this->useBinary = (bool) $useBinary;
     if ($this->useBinary && Version::compare('2.5.0') >= 0) {
         throw new \InvalidArgumentException('The Binary storage is only available with Doctrine DBAL >= 2.5.0');
     }
 }
 public function setUp()
 {
     if (Version::compare('2.5.0') >= 0) {
         $this->markTestSkipped('Binary type is only available for Doctrine >= v2.5');
     }
     $connection = DriverManager::getConnection(array('driver' => 'pdo_sqlite', 'memory' => true));
     $schemaManager = $connection->getSchemaManager();
     $schema = $schemaManager->createSchema();
     $this->eventStore = new DBALEventStore($connection, new SimpleInterfaceSerializer(), new SimpleInterfaceSerializer(), 'events', true);
     $this->table = $this->eventStore->configureSchema($schema);
     $schemaManager->createTable($this->table);
 }
Exemple #4
0
 /**
  * {@inheritDoc}
  */
 public function getConfigTreeBuilder()
 {
     $treeBuilder = new TreeBuilder();
     $rootNode = $treeBuilder->root('broadway');
     $rootNode->children()->arrayNode('command_handling')->addDefaultsIfNotSet()->children()->scalarNode('logger')->defaultFalse()->end()->end()->end()->arrayNode('event_store')->addDefaultsIfNotSet()->children()->arrayNode('dbal')->addDefaultsIfNotSet()->children()->scalarNode('table')->defaultValue('events')->end()->scalarNode('connection')->defaultValue('default')->end()->booleanNode('use_binary')->defaultFalse()->validate()->ifTrue()->then(function ($v) {
         if (Version::compare('2.5.0') >= 0) {
             throw new InvalidConfigurationException('The Binary storage is only available with Doctrine DBAL >= 2.5.0');
         }
         return $v;
     })->end()->end()->end()->end()->end()->end()->arrayNode('saga')->addDefaultsIfNotSet()->children()->enumNode('repository')->values(array('in_memory', 'mongodb'))->defaultValue('mongodb')->end()->arrayNode('mongodb')->addDefaultsIfNotSet()->children()->arrayNode('connection')->children()->scalarNode('dsn')->defaultNull()->end()->scalarNode('database')->defaultNull()->end()->arrayNode('options')->prototype('scalar')->end()->end()->end()->end()->scalarNode('storage_suffix')->defaultNull()->end()->end()->end()->end()->end()->arrayNode('read_model')->addDefaultsIfNotSet()->children()->enumNode('repository')->values(array('in_memory', 'elasticsearch'))->defaultValue('elasticsearch')->end()->arrayNode('elasticsearch')->addDefaultsIfNotSet()->children()->arrayNode('hosts')->beforeNormalization()->ifTrue(function ($v) {
         return is_string($v);
     })->then(function ($v) {
         return array($v);
     })->end()->defaultValue(array('localhost:9200'))->prototype('scalar')->end()->end()->arrayNode('connectionParams')->children()->arrayNode('auth')->prototype('scalar')->end()->end()->end()->end()->end()->end()->end()->end();
     return $treeBuilder;
 }
 /**
  * Generate sql queries and create new migration class
  * 
  * @param InputInterface  $input
  * @param OutputInterface $output
  * 
  * @return null
  * @throws \InvalidArgumentException
  */
 public function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output)
 {
     $isDbalOld = DbalVersion::compare('2.2.0') > 0;
     $configuration = $this->getMigrationConfiguration($input, $output);
     $em = $this->getHelper('em')->getEntityManager();
     $conn = $em->getConnection();
     $platform = $conn->getDatabasePlatform();
     $metadata = $em->getMetadataFactory()->getAllMetadata();
     if (empty($metadata)) {
         $output->writeln('No mapping information to process.', 'ERROR');
         return;
     }
     if ($filterExpr = $input->getOption('filter-expression')) {
         if ($isDbalOld) {
             throw new \InvalidArgumentException('The "--filter-expression" option can only be used as of Doctrine DBAL 2.2');
         }
         $conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpr);
     }
     $tool = new SchemaTool($em);
     $fromSchema = $conn->getSchemaManager()->createSchema();
     $toSchema = $tool->getSchemaFromMetadata($metadata);
     foreach ($fromSchema->getTables() as $tableName => $table) {
         if (!$toSchema->hasTable($tableName)) {
             // if drop the table from the $fromSchema, could not generate the DROP TABLE sql
             $fromSchema->dropTable($tableName);
         }
     }
     //Not using value from options, because filters can be set from config.yml
     if (!$isDbalOld && ($filterExpr = $conn->getConfiguration()->getFilterSchemaAssetsExpression())) {
         $tableNames = $toSchema->getTableNames();
         foreach ($tableNames as $tableName) {
             $tableName = substr($tableName, strpos($tableName, '.') + 1);
             if (!preg_match($filterExpr, $tableName)) {
                 $toSchema->dropTable($tableName);
             }
         }
     }
     $up = $this->buildCodeFromSql($configuration, $fromSchema->getMigrateToSql($toSchema, $platform));
     $down = $this->buildCodeFromSql($configuration, $fromSchema->getMigrateFromSql($toSchema, $platform));
     if (!$up && !$down) {
         $output->writeln('No changes detected in your mapping information.', 'ERROR');
         return;
     }
     $version = date('YmdHis');
     $path = $this->generateMigration($configuration, $input, $version, $up, $down);
     $output->writeln(sprintf('Generated new migration class to "<info>%s</info>" from schema differences.', $path));
 }
Exemple #6
0
 /**
  * Checks the dependent ORM library components
  * for compatibility
  *
  * @throws DependentComponentNotFoundException
  * @throws IncompatibleComponentVersionException
  */
 public static function checkORMDependencies()
 {
     // doctrine common library
     if (!class_exists('Doctrine\\Common\\Version')) {
         throw new DependentComponentNotFoundException("Doctrine\\Common library is either not registered by autoloader or not installed");
     }
     if (\Doctrine\Common\Version::compare(self::VERSION) > 0) {
         throw new IncompatibleComponentVersionException("Doctrine\\Common library is older than expected for these extensions");
     }
     // doctrine dbal library
     if (!class_exists('Doctrine\\DBAL\\Version')) {
         throw new DependentComponentNotFoundException("Doctrine\\DBAL library is either not registered by autoloader or not installed");
     }
     if (\Doctrine\DBAL\Version::compare(self::VERSION) > 0) {
         throw new IncompatibleComponentVersionException("Doctrine\\DBAL library is older than expected for these extensions");
     }
     // doctrine ORM library
     if (!class_exists('Doctrine\\ORM\\Version')) {
         throw new DependentComponentNotFoundException("Doctrine\\ORM library is either not registered by autoloader or not installed");
     }
     if (\Doctrine\ORM\Version::compare(self::VERSION) > 0) {
         throw new IncompatibleComponentVersionException("Doctrine\\ORM library is older than expected for these extensions");
     }
 }
Exemple #7
0
 protected function isDbalOld()
 {
     return DbalVersion::compare('2.2.0') > 0;
 }
Exemple #8
0
 /**
  * the ping method is new in doctrine dbal at version 2.5.*
  * @link http://www.doctrine-project.org/2014/01/01/dbal-242-252beta1.html
  * @link https://packagist.org/packages/doctrine/dbal
  * @return mixed
  */
 public function ping()
 {
     return Version::compare('2.5') >= 0 ? $this->conn->ping() : true;
 }