Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Enh #317: Explicitly import classes, functions, and constants in "use" section (@mspirkov)
- Enh #318: Remove unnecessary files from Composer package (@mspirkov)
- Enh #319: Remove confirmation prompt from `migrate:create` command as creating a migration is non-destructive (@samdark)

## 2.0.1 December 20, 2025

Expand Down
61 changes: 19 additions & 42 deletions src/Command/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Style\SymfonyStyle;
use Yiisoft\Db\Migration\Migrator;
use Yiisoft\Db\Migration\Service\Generate\CreateService;
Expand Down Expand Up @@ -88,7 +86,6 @@ protected function configure(): void
->addOption('and', null, InputOption::VALUE_REQUIRED, 'And junction.')
->addOption('path', null, InputOption::VALUE_REQUIRED, 'Path to migration directory.')
->addOption('namespace', 'ns', InputOption::VALUE_REQUIRED, 'Migration file namespace.')
->addOption('force-yes', 'y', InputOption::VALUE_NONE, 'Force yes to all questions.')
->setHelp('This command generates new migration file.');
}

Expand Down Expand Up @@ -159,54 +156,34 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::INVALID;
}

if ($this->confirm($input, $output)) {
/** @var string|null $fields */
$fields = $input->getOption('fields');
/** @var string|null $tableComment */
$tableComment = $input->getOption('table-comment');

$content = $this->createService->run(
$command,
$table,
$className,
$namespace,
$fields,
$and,
$tableComment,
);
/** @var string|null $fields */
$fields = $input->getOption('fields');
/** @var string|null $tableComment */
$tableComment = $input->getOption('table-comment');

$content = $this->createService->run(
$command,
$table,
$className,
$namespace,
$fields,
$and,
$tableComment,
);

$file = $migrationPath . DIRECTORY_SEPARATOR . $className . '.php';
$file = $migrationPath . DIRECTORY_SEPARATOR . $className . '.php';

file_put_contents($file, $content, LOCK_EX);
file_put_contents($file, $content, LOCK_EX);

$output->writeln("\n\t<info>$className</info>");
$output->writeln("\n");
$io->success('New migration created successfully.');
}
$output->writeln("\n\t<info>$className</info>");
$output->writeln("\n");
$io->success('New migration created successfully.');

$this->migrationService->databaseConnection();

return Command::SUCCESS;
}

private function confirm(InputInterface $input, OutputInterface $output): bool
{
if ($input->getOption('force-yes')) {
return true;
}

$question = new ConfirmationQuestion(
"\n<fg=cyan>Create new migration y/n: </>",
false,
);

/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');

/** @var bool */
return $helper->ask($input, $output, $question);
}

private function generateName(string $command, string $name, ?string $and): string
{
$result = '';
Expand Down
3 changes: 2 additions & 1 deletion src/MigrationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Yiisoft\Db\Migration\Informer\MigrationInformerInterface;
use Yiisoft\Db\Schema\Column\ColumnBuilder;
use Yiisoft\Db\Schema\Column\ColumnInterface;
use Yiisoft\Db\Command\CommandInterface;

use function implode;
use function ltrim;
Expand Down Expand Up @@ -65,7 +66,7 @@ public function getDb(): ConnectionInterface
* @throws InvalidConfigException
* @throws NotSupportedException
*
* @see \Yiisoft\Db\Command\CommandInterface::execute() for more details.
* @see CommandInterface::execute() for more details.
*/
public function execute(string $sql, array $params = []): void
{
Expand Down
Loading
Loading