Skip to content

Commit

Permalink
Override base refresh command.
Browse files Browse the repository at this point in the history
Signed-off-by: crynobone <[email protected]>
  • Loading branch information
crynobone committed Aug 24, 2017
1 parent 4f7ce6d commit 513de63
Showing 1 changed file with 61 additions and 12 deletions.
73 changes: 61 additions & 12 deletions Console/Migrations/RefreshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,79 @@ public function fire()
return;
}

$database = $this->input->getOption('database');
$force = $this->input->getOption('force');
$path = $this->input->getOption('path');
$realpath = $this->input->getOption('realpath');
// Next we'll gather some of the options so that we can have the right options
// to pass to the commands. This includes options such as which database to
// use and the path to use for the migration. Then we'll run the command.
$database = $this->option('database');

$this->call('migrate:reset', [
'--database' => $database,
'--force' => $force,
]);
$path = $this->option('path');

$force = $this->option('force');

// If the "step" option is specified it means we only want to rollback a small
// number of migrations before migrating again. For example, the user might
// only rollback and remigrate the latest four migrations instead of all.
$step = $this->option('step') ?: 0;

if ($step > 0) {
$this->runRollback($database, $path, $step, $force);
} else {
$this->runReset($database, $path, $force);
}

// The refresh command is essentially just a brief aggregate of a few other of
// the migration commands and just provides a convenient wrapper to execute
// them in succession. We'll also see if we need to re-seed the database.
$this->call('migrate', [
'--database' => $database,
'--force' => $force,
'--path' => $path,
'--realpath' => $realpath,
'--path' => $path,
'--realpath' => $this->option('realpath'),
'--force' => $force,
]);

if ($this->needsSeeding()) {
$this->runSeeder($database);
}
}

/**
* Run the rollback command.
*
* @param string $database
* @param string $path
* @param bool $step
* @param bool $force
* @return void
*/
protected function runRollback($database, $path, $step, $force)
{
$this->call('migrate:rollback', [
'--database' => $database,
'--path' => $path,
'--realpath' => $this->option('realpath'),
'--step' => $step,
'--force' => $force,
]);
}

/**
* Run the reset command.
*
* @param string $database
* @param string $path
* @param bool $force
* @return void
*/
protected function runReset($database, $paths, $force)
{
$this->call('migrate:reset', [
'--database' => $database,
'--path' => $path,
'--realpath' => $this->option('realpath'),
'--force' => $force,
]);
}

/**
* Get the console command options.
*
Expand All @@ -53,10 +101,11 @@ protected function getOptions()
return [
['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'],
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'],
['realpath', null, InputOption::VALUE_OPTIONAL, 'The absolute path to migration files.', null],
['path', null, InputOption::VALUE_OPTIONAL, 'The path of migrations files to be executed.'],
['realpath', null, InputOption::VALUE_OPTIONAL, 'The absolute path to migration files.', null],
['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'],
['seeder', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder.'],
['step', null, InputOption::VALUE_OPTIONAL, 'The number of migrations to be reverted & re-run.'],
];
}
}

0 comments on commit 513de63

Please sign in to comment.