48 lines
1.6 KiB
PHP
48 lines
1.6 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Nest\Database\Cli\Migrations;
|
||
|
|
||
|
use Nest\Cli\Cli;
|
||
|
use Nest\Cli\Commands\CommandDefinition;
|
||
|
use Nest\Cli\Commands\ParameterDefinition;
|
||
|
use Nest\Cli\Exceptions\Command\InvalidCommandHandlerException;
|
||
|
use Nest\Cli\Exceptions\IncompatibleCliHandlerSubcommands;
|
||
|
|
||
|
/**
|
||
|
* Migrations commands definition manager.
|
||
|
*/
|
||
|
class MigrationsCommands
|
||
|
{
|
||
|
/**
|
||
|
* @param Cli $cli The CLI in which to define migrations commands.
|
||
|
* @return void
|
||
|
* @throws IncompatibleCliHandlerSubcommands
|
||
|
* @throws InvalidCommandHandlerException
|
||
|
*/
|
||
|
public static function define(Cli $cli): void
|
||
|
{
|
||
|
$cli->command("migrations")
|
||
|
->description("Migrations manager.")
|
||
|
->subcommands([
|
||
|
"migrate" => fn (CommandDefinition $subcommand) => $subcommand
|
||
|
->description("Execute all remaining migrations.")
|
||
|
->handler(MigrateCommand::class)
|
||
|
,
|
||
|
"migrateOne" => fn (CommandDefinition $subcommand) => $subcommand
|
||
|
->description("Perform one migration.")
|
||
|
->parameter("migrationId", fn (ParameterDefinition $parameter) => $parameter->description("Migration ID of migration to execute."))
|
||
|
->handler(MigrateOneCommand::class)
|
||
|
,
|
||
|
"rollback" => fn (CommandDefinition $subcommand) => $subcommand
|
||
|
->description("Rollback latest migration.")
|
||
|
->handler(RollbackCommand::class)
|
||
|
,
|
||
|
"new" => fn (CommandDefinition $subcommand) => $subcommand
|
||
|
->description("Generate a migration with the given name.")
|
||
|
->parameter("name", fn (ParameterDefinition $parameter) => $parameter->description("Name of the new migration."))
|
||
|
->handler(NewCommand::class)
|
||
|
,
|
||
|
]);
|
||
|
}
|
||
|
}
|