Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function execSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
 {
     // Defining if update is complete or not (--complete not defined means $saveMode = true)
     $saveMode = !$input->getOption('complete');
     $sqls = $schemaTool->getUpdateSchemaSql($metadatas, $saveMode);
     if (0 === count($sqls)) {
         $output->writeln('Nothing to update - your database is already in sync with the current entity metadata.');
         return 0;
     }
     $dumpSql = true === $input->getOption('dump-sql');
     $force = true === $input->getOption('force');
     if ($dumpSql) {
         $output->writeln(implode(';' . PHP_EOL, $sqls) . ';');
     }
     if ($force) {
         if ($dumpSql) {
             $output->writeln('');
         }
         $output->writeln('Updating database schema...');
         $schemaTool->updateSchema($metadatas, $saveMode);
         $output->writeln(sprintf('Database schema updated successfully! "<info>%s</info>" queries were executed', count($sqls)));
     }
     if ($dumpSql || $force) {
         return 0;
     }
     $output->writeln('<comment>ATTENTION</comment>: This operation should not be executed in a production environment.');
     $output->writeln('           Use the incremental update to detect changes during development and use');
     $output->writeln('           the SQL DDL provided to manually update your database in production.');
     $output->writeln('');
     $output->writeln(sprintf('The Schema-Tool would execute <info>"%s"</info> queries to update the database.', count($sqls)));
     $output->writeln('Please run the operation by passing one - or both - of the following options:');
     $output->writeln(sprintf('    <info>%s --force</info> to execute the command', $this->getName()));
     $output->writeln(sprintf('    <info>%s --dump-sql</info> to dump the SQL statements to the screen', $this->getName()));
     return 1;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 protected function execSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
 {
     if ($input->getOption('dump-sql')) {
         $sqls = $schemaTool->getCreateSchemaSql($metadatas);
         $output->writeln(implode(';' . PHP_EOL, $sqls) . ';');
     } else {
         $output->writeln('ATTENTION: This operation should not be executed in a production environment.' . PHP_EOL);
         $output->writeln('Creating database schema...');
         $schemaTool->createSchema($metadatas);
         $output->writeln('Database schema created successfully!');
     }
     return 0;
 }