Final Class Yiisoft\Db\Migration\Command\HistoryCommand
| Inheritance | Yiisoft\ |
|---|
Displays the migration history.
This command will show the list of migrations that have been applied so far.
For example:
./yii migrate:history # last 10 migrations
./yii migrate:history --limit=5 # last 5 migrations
./yii migrate:history --all # whole history
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| configure() | Yiisoft\ |
|
| execute() | Yiisoft\ |
Method Details
| public mixed __construct ( Yiisoft\ | ||
| $migrationService | Yiisoft\ |
|
| $migrator | Yiisoft\ |
|
public function __construct(
private readonly MigrationService $migrationService,
private readonly Migrator $migrator,
) {
parent::__construct();
}
| protected void configure ( ) |
protected function configure(): void
{
$this
->addOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Number of migrations to display.', 10)
->addOption('all', 'a', InputOption::VALUE_NONE, 'All migrations.');
}
| protected integer execute ( \ | ||
| $input | \ |
|
| $output | \ |
|
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$this->migrator->setIo($io);
$this->migrationService->setIo($io);
$this->migrationService->databaseConnection();
$this->migrationService->before($this->getName() ?? '');
$limit = !$input->getOption('all')
? (int) $input->getOption('limit')
: null;
if ($limit !== null && $limit <= 0) {
$io->error('The limit option must be greater than 0.');
return Command::INVALID;
}
$migrations = $this->migrator->getHistory($limit);
if (empty($migrations)) {
$io->warning('No migration has been done before.');
return Command::FAILURE;
}
$countMigrations = count($migrations);
if ($limit === $countMigrations) {
$io->section("Last $countMigrations applied " . ($countMigrations === 1 ? 'migration' : 'migrations') . ':');
} else {
$io->section("Total $countMigrations " . ($countMigrations === 1 ? 'migration has' : 'migrations have') . ' been applied before:');
}
foreach ($migrations as $version => $time) {
$output->writeln("\t<info>(" . date('Y-m-d H:i:s', (int) $time) . ') ' . $version . '</info>');
}
$output->writeln("\n" );
$io->success('Success.');
return Command::SUCCESS;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.