Example #1
0
 /**
  * @return $this
  */
 protected function getDropTables()
 {
     $tables = $this->dbService->getBaseTables();
     foreach ($tables as $table) {
         if (!$this->dbService->targetHasTable($table)) {
             $this->changes['dropTables'][] = $this->dbService->getDropStatement($table);
         }
     }
     return $this;
 }
 /**
  * Create DbService instance based on CLI options, prompt for pass
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return DbService
  */
 private function getDbService(InputInterface $input, OutputInterface $output)
 {
     $base = $input->getOption('base');
     if (!$base) {
         $output->writeln('<error>Missing base DB name</error>');
         return null;
     }
     $this->arguments['base'] = $base;
     $this->arguments['host'] = $input->getOption('host');
     $this->arguments['username'] = $input->getOption('username');
     $this->arguments['file'] = $input->getOption('file');
     $this->arguments['password'] = (string) $this->dialog->askHiddenResponse($output, '<question>Please enter the DB password (default "")</question>', $this->arguments['password']);
     $target = $input->getOption('target');
     $schemaFile = null;
     if (!$target) {
         $target = 'compare_' . date('YmdHis');
         $output->writeln(sprintf('<info>Missing target DB name - creating schema %s</info>', $target));
         $schemaFile = $this->dialog->ask($output, '<question>File to create base schema</question>', null);
         if (!$schemaFile || !file_exists($schemaFile)) {
             $output->writeln(sprintf('<error>Invalid schema file: %s</error>', $schemaFile));
             return null;
         }
     }
     $this->arguments['target'] = $target;
     $service = new DbService($this->arguments['host'], $this->arguments['username'], $this->arguments['password'], $this->arguments['base'], $this->arguments['target']);
     $this->dropSchema = $schemaFile !== null;
     //ensure schemas exist, create target schema if required
     $service->checkSchemas($this->dropSchema);
     if ($schemaFile) {
         $service->loadTargetSchema($schemaFile);
     }
     return $service;
 }