ResetCommand.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 ResetCommand extends BaseCommand
  7. {
  8. use ConfirmableTrait;
  9. /**
  10. * The console command name.
  11. *
  12. * @var string
  13. */
  14. protected $name = 'migrate:reset';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Rollback all database migrations';
  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. // First, we'll make sure that the migration table actually exists before we
  50. // start trying to rollback and re-run all of the migrations. If it's not
  51. // present we'll just bail out with an info message for the developers.
  52. if (! $this->migrator->repositoryExists()) {
  53. return $this->comment('Migration table not found.');
  54. }
  55. $this->migrator->setOutput($this->output)->reset(
  56. $this->getMigrationPaths(), $this->option('pretend')
  57. );
  58. }
  59. /**
  60. * Get the console command options.
  61. *
  62. * @return array
  63. */
  64. protected function getOptions()
  65. {
  66. return [
  67. ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use'],
  68. ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production'],
  69. ['path', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The path(s) to the migrations files to be executed'],
  70. ['realpath', null, InputOption::VALUE_NONE, 'Indicate any provided migration file paths are pre-resolved absolute paths'],
  71. ['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run'],
  72. ];
  73. }
  74. }