Last active
December 30, 2015 15:39
-
-
Save hkan/7849565 to your computer and use it in GitHub Desktop.
Laravel Artisan Auto Migration Command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Console\Command; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Input\InputArgument; | |
class InstallCommand extends Command { | |
/** | |
* The console command name. | |
* | |
* @var string | |
*/ | |
protected $name = 'migrate:auto'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Automatically does migrations and seedings.'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return void | |
*/ | |
public function fire() | |
{ | |
if ( ! Schema::hasTable(Config::get('database.migrations'))) | |
$this->call('migrate:install'); | |
// is fresh install | |
if ($this->option('fresh')) | |
{ | |
$this->call('migrate:reset'); | |
} | |
if (Config::get('session.driver') == 'database') | |
$this->call('session:table'); | |
$this->call('migrate'); | |
// is seed enabled | |
if ($this->option('seed')) | |
{ | |
$this->call('db:seed'); | |
} | |
} | |
/** | |
* Get the console command arguments. | |
* | |
* @return array | |
*/ | |
protected function getArguments() | |
{ | |
return array(); | |
} | |
/** | |
* Get the console command options. | |
* | |
* @return array | |
*/ | |
protected function getOptions() | |
{ | |
return array( | |
array('fresh', null, InputOption::VALUE_OPTIONAL, 'Fresh installation', false), | |
array('seed', null, InputOption::VALUE_OPTIONAL, 'Seed tables', true) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment