diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php index 0d6741717..af6d8d026 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php @@ -49,13 +49,17 @@ class DropCommand extends AbstractCommand $this ->setName('orm:schema-tool:drop') ->setDescription( - 'Processes the schema and either drop the database schema of EntityManager Storage Connection or generate the SQL output.' + 'Drop the complete database schema of EntityManager Storage Connection or generate the corresponding SQL output.' ) ->setDefinition(array( new InputOption( 'dump-sql', null, InputOption::PARAMETER_NONE, 'Instead of try to apply generated SQLs into EntityManager Storage Connection, output them.' - ) + ), + new InputOption( + 'force', null, InputOption::PARAMETER_NONE, + "Don't ask for the deletion of the database, but force the operation to run." + ), )) ->setHelp(<<getOption('dump-sql') === true) { $sqls = $schemaTool->getDropSchemaSql($metadatas); $output->write(implode(';' . PHP_EOL, $sqls) . PHP_EOL); - } else { + } else if ($input->getOption('force') === true) { $output->write('Dropping database schema...' . PHP_EOL); $schemaTool->dropSchema($metadatas); $output->write('Database schema dropped successfully!' . PHP_EOL); + } else { + $sqls = $schemaTool->getDropSchemaSql($metadatas); + + if (count($sqls)) { + $output->write('Schema-Tool would execute ' . count($sqls) . ' queries to drop the database.' . PHP_EOL); + $output->write('Please run the operation with --force to execute these queries or use --dump-sql to see them.' . PHP_EOL); + } else { + $output->write('Nothing to drop. The database is empty!' . PHP_EOL); + } } } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php index 986d97954..193d8acc9 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php @@ -59,7 +59,11 @@ class UpdateCommand extends AbstractCommand new InputOption( 'dump-sql', null, InputOption::PARAMETER_NONE, 'Instead of try to apply generated SQLs into EntityManager Storage Connection, output them.' - ) + ), + new InputOption( + 'force', null, InputOption::PARAMETER_NONE, + "Don't ask for the deletion of the database, but force the operation to run." + ), )) ->setHelp(<<getOption('complete') === true); + $saveMode = ($input->getOption('complete') !== true); if ($input->getOption('dump-sql') === true) { $sqls = $schemaTool->getUpdateSchemaSql($metadatas, $saveMode); $output->write(implode(';' . PHP_EOL, $sqls) . PHP_EOL); - } else { + } else if ($input->getOption('force') === true) { $output->write('Updating database schema...' . PHP_EOL); $schemaTool->updateSchema($metadatas, $saveMode); $output->write('Database schema updated successfully!' . PHP_EOL); + } else { + $sqls = $schemaTool->getUpdateSchemaSql($metadatas, $saveMode); + + if (count($sqls)) { + $output->write('Schema-Tool would execute ' . count($sqls) . ' queries to update the database.' . PHP_EOL); + $output->write('Please run the operation with --force to execute these queries or use --dump-sql to see them.' . PHP_EOL); + } else { + $output->write('Nothing to update. The database is in sync with the current entity metadata.' . PHP_EOL); + } } } }