diff --git a/src/Command/SyncCommand.php b/src/Command/SyncCommand.php index fea12e7..41b191a 100644 --- a/src/Command/SyncCommand.php +++ b/src/Command/SyncCommand.php @@ -6,6 +6,7 @@ use DbSync\Hash\Md5Hash; use DbSync\Table; use DbSync\Transfer\Transfer; +use DbSync\WhereClause; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputArgument; @@ -60,7 +61,7 @@ protected function configure() ->addOption('target.user',null , InputOption::VALUE_REQUIRED, 'The name of the user to connect to the target host with if different to the source.') ->addOption('target.table',null , InputOption::VALUE_REQUIRED, 'The name of the table on the target host if different to the source.') ->addOption('target.password',null , InputOption::VALUE_REQUIRED, 'The password for the target host if the target user is specified. Will be solicited on the tty if not given.') - //->addOption('where', null , InputOption::VALUE_REQUIRED, 'A where clause to apply to the source table') + ->addOption('where', null , InputOption::VALUE_REQUIRED, 'A where clause to apply to the tables') ; } @@ -153,9 +154,18 @@ private function fire() $sync->setLogger($logger); + $sourceTableObj = new Table($source, $sourceDatabase, $sourceTable); + $destTableObj = new Table($target, $targetDatabase, $targetTable); + + if($where = $this->input->getOption('where')) + { + $sourceTableObj->setWhereClause(new WhereClause($where)); + $destTableObj->setWhereClause(new WhereClause($where)); + } + $result = $sync->sync( - new Table($source, $sourceDatabase, $sourceTable), - new Table($target, $targetDatabase, $targetTable), + $sourceTableObj, + $destTableObj, new ColumnConfiguration($this->input->getOption('columns'), $this->input->getOption('ignore-columns')) ); diff --git a/tests/integration/FullSyncTest.php b/tests/integration/FullSyncTest.php index 8fccaac..4cc7278 100644 --- a/tests/integration/FullSyncTest.php +++ b/tests/integration/FullSyncTest.php @@ -5,9 +5,13 @@ class FullSyncTest extends PHPUnit_Framework_TestCase protected $connection; + protected $config; + public function setUp() { - $this->connection = (new \Database\Connectors\ConnectionFactory())->make(include __DIR__ . '/config.php'); + $this->config = include __DIR__ . '/config.php'; + + $this->connection = (new \Database\Connectors\ConnectionFactory())->make($this->config); } public function providerHashStrategy() @@ -19,6 +23,23 @@ public function providerHashStrategy() ); } + public function testItRunsCommand() + { + $this->createTestDatabases(); + + $db = self::DATABASE; + + $host = $this->config['host']; + $user = $this->config['username']; + $password = $this->config['password']; + + $command = __DIR__ . "/../../bin/sync $host $host $db.customers1 --target.table=$db.customers2 -u $user -p $password -e"; + + exec($command, $output, $code); + + $this->assertEquals(0, $code); + } + /** * @dataProvider providerHashStrategy */