setAliases(['rollup'])
->setDescription('Rollup migrations by deleting all tracked versions and insert the one version that exists.')
->setHelp(<<<'EOT'
The %command.name% command rolls up migrations by deleting all tracked versions and
inserts the one version that exists that was created with the migrations:dump-schema command.
%command.full_name%
To dump your schema to a migration version you can use the migrations:dump-schema command.
EOT);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$question = sprintf(
'WARNING! You are about to execute a migration in database "%s" that could result in schema changes and data loss. Are you sure you wish to continue?',
$this->getDependencyFactory()->getConnection()->getDatabase() ?? '',
);
if (! $this->canExecute($question, $input)) {
$this->io->error('Migration cancelled!');
return 3;
}
$this->getDependencyFactory()->getMetadataStorage()->ensureInitialized();
$version = $this->getDependencyFactory()->getRollup()->rollup();
$this->io->success(sprintf(
'Rolled up migrations to version %s',
(string) $version,
));
return 0;
}
}