Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

RollbackCommand.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Illuminate\Database\Console\Migrations;
  3. use Illuminate\Console\ConfirmableTrait;
  4. use Illuminate\Database\Migrations\Migrator;
  5. use Symfony\Component\Console\Input\InputOption;
  6. class RollbackCommand extends BaseCommand
  7. {
  8. use ConfirmableTrait;
  9. /**
  10. * The console command name.
  11. *
  12. * @var string
  13. */
  14. protected $name = 'migrate:rollback';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Rollback the last database migration';
  21. /**
  22. * The migrator instance.
  23. *
  24. * @var \Illuminate\Database\Migrations\Migrator
  25. */
  26. protected $migrator;
  27. /**
  28. * Create a new migration rollback command instance.
  29. *
  30. * @param \Illuminate\Database\Migrations\Migrator $migrator
  31. * @return void
  32. */
  33. public function __construct(Migrator $migrator)
  34. {
  35. parent::__construct();
  36. $this->migrator = $migrator;
  37. }
  38. /**
  39. * Execute the console command.
  40. *
  41. * @return void
  42. */
  43. public function handle()
  44. {
  45. if (! $this->confirmToProceed()) {
  46. return;
  47. }
  48. $this->migrator->setConnection($this->option('database'));
  49. $this->migrator->setOutput($this->output)->rollback(
  50. $this->getMigrationPaths(), [
  51. 'pretend' => $this->option('pretend'),
  52. 'step' => (int) $this->option('step'),
  53. ]
  54. );
  55. }
  56. /**
  57. * Get the console command options.
  58. *
  59. * @return array
  60. */
  61. protected function getOptions()
  62. {
  63. return [
  64. ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use'],
  65. ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production'],
  66. ['path', null, InputOption::VALUE_OPTIONAL, 'The path to the migrations files to be executed'],
  67. ['realpath', null, InputOption::VALUE_NONE, 'Indicate any provided migration file paths are pre-resolved absolute paths'],
  68. ['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run'],
  69. ['step', null, InputOption::VALUE_OPTIONAL, 'The number of migrations to be reverted'],
  70. ];
  71. }
  72. }