/**
  * Execute the console command.
  *
  * @param ConfigurationProvider  $provider
  * @param ManagerRegistry        $registry
  * @param SqlBuilder             $builder
  * @param MigrationFileGenerator $generator
  */
 public function fire(ConfigurationProvider $provider, ManagerRegistry $registry, SqlBuilder $builder, MigrationFileGenerator $generator)
 {
     $configuration = $provider->getForConnection($this->option('connection'));
     $em = $registry->getManager($this->option('connection'));
     $connection = $configuration->getConnection();
     // Overrule the filter
     if ($filterExpr = $this->option('filter-expression')) {
         $connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpr);
     }
     $fromSchema = $connection->getSchemaManager()->createSchema();
     $toSchema = $this->getSchemaProvider($em)->createSchema();
     // Drop tables which don't suffice to the filter regex
     if ($filterExpr = $connection->getConfiguration()->getFilterSchemaAssetsExpression()) {
         foreach ($toSchema->getTables() as $table) {
             $tableName = $table->getName();
             if (!preg_match($filterExpr, $this->resolveTableName($tableName))) {
                 $toSchema->dropTable($tableName);
             }
         }
     }
     $up = $builder->up($configuration, $fromSchema, $toSchema);
     $down = $builder->down($configuration, $fromSchema, $toSchema);
     if (!$up && !$down) {
         return $this->error('No changes detected in your mapping information.');
     }
     $path = $generator->generate($configuration, false, false, $up, $down);
     $this->line(sprintf('Generated new migration class to "<info>%s</info>" from schema differences.', $path));
 }
 public function test_can_build_down_sql()
 {
     $this->from->shouldReceive('getMigrateFromSql')->with($this->to, $this->platform)->andReturn(['QUERY3', 'QUERY4']);
     $sql = $this->builder->down($this->configuration, $this->from, $this->to);
     $this->assertEquals(trim(file_get_contents(__DIR__ . '/../stubs/down.stub')), $sql);
 }