BaseCommand.php
2 years ago
FreshCommand.php
3 weeks ago
InstallCommand.php
3 weeks ago
MigrateCommand.php
3 weeks ago
MigrateMakeCommand.php
3 weeks ago
RefreshCommand.php
2 years ago
ResetCommand.php
3 weeks ago
RollbackCommand.php
2 years ago
StatusCommand.php
3 weeks ago
TableGuesser.php
2 years ago
ResetCommand.php
71 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWPSCOPED\Illuminate\Database\Console\Migrations; |
| 4 | |
| 5 | use IAWPSCOPED\Illuminate\Console\ConfirmableTrait; |
| 6 | use IAWPSCOPED\Illuminate\Database\Migrations\Migrator; |
| 7 | use IAWPSCOPED\Symfony\Component\Console\Input\InputOption; |
| 8 | /** @internal */ |
| 9 | class ResetCommand extends BaseCommand |
| 10 | { |
| 11 | use ConfirmableTrait; |
| 12 | /** |
| 13 | * The console command name. |
| 14 | * |
| 15 | * @var string |
| 16 | */ |
| 17 | protected $name = 'migrate:reset'; |
| 18 | /** |
| 19 | * The console command description. |
| 20 | * |
| 21 | * @var string |
| 22 | */ |
| 23 | protected $description = 'Rollback all database migrations'; |
| 24 | /** |
| 25 | * The migrator instance. |
| 26 | * |
| 27 | * @var \Illuminate\Database\Migrations\Migrator |
| 28 | */ |
| 29 | protected $migrator; |
| 30 | /** |
| 31 | * Create a new migration rollback command instance. |
| 32 | * |
| 33 | * @param \Illuminate\Database\Migrations\Migrator $migrator |
| 34 | * @return void |
| 35 | */ |
| 36 | public function __construct(Migrator $migrator) |
| 37 | { |
| 38 | parent::__construct(); |
| 39 | $this->migrator = $migrator; |
| 40 | } |
| 41 | /** |
| 42 | * Execute the console command. |
| 43 | * |
| 44 | * @return int |
| 45 | */ |
| 46 | public function handle() |
| 47 | { |
| 48 | if (!$this->confirmToProceed()) { |
| 49 | return 1; |
| 50 | } |
| 51 | return $this->migrator->usingConnection($this->option('database'), function () { |
| 52 | // First, we'll make sure that the migration table actually exists before we |
| 53 | // start trying to rollback and re-run all of the migrations. If it's not |
| 54 | // present we'll just bail out with an info message for the developers. |
| 55 | if (!$this->migrator->repositoryExists()) { |
| 56 | return $this->components->warn('Migration table not found.'); |
| 57 | } |
| 58 | $this->migrator->setOutput($this->output)->reset($this->getMigrationPaths(), $this->option('pretend')); |
| 59 | }); |
| 60 | } |
| 61 | /** |
| 62 | * Get the console command options. |
| 63 | * |
| 64 | * @return array |
| 65 | */ |
| 66 | protected function getOptions() |
| 67 | { |
| 68 | return [['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], ['path', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The path(s) to the migrations files to be executed'], ['realpath', null, InputOption::VALUE_NONE, 'Indicate any provided migration file paths are pre-resolved absolute paths'], ['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run']]; |
| 69 | } |
| 70 | } |
| 71 |