/** * 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_up_sql() { $this->from->shouldReceive('getMigrateToSql')->with($this->to, $this->platform)->andReturn(['QUERY1', 'QUERY2']); $sql = $this->builder->up($this->configuration, $this->from, $this->to); $this->assertEquals(trim(file_get_contents(__DIR__ . '/../stubs/up.stub')), $sql); }