/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$this->info('Using connection: ' . $this->option('connection') . "\n");
$this->schemaGenerator = new SchemaGenerator($this->option('connection'), $this->option('defaultIndexNames'), $this->option('defaultFKNames'));
if ($this->argument('tables')) {
$tables = explode(',', $this->argument('tables'));
} elseif ($this->option('tables')) {
$tables = explode(',', $this->option('tables'));
} else {
$tables = $this->schemaGenerator->getTables();
}
$tables = $this->removeExcludedTables($tables);
$this->info('Generating migrations for: ' . implode(', ', $tables));
if (!$this->option('no-interaction')) {
$this->log = $this->askYn('Do you want to log these migrations in the migrations table?');
}
if ($this->log) {
$this->repository->setSource($this->option('connection'));
if (!$this->repository->repositoryExists()) {
$options = array('--database' => $this->option('connection'));
$this->call('migrate:install', $options);
}
$batch = $this->repository->getNextBatchNumber();
$this->batch = $this->askNumeric('Next Batch Number is: ' . $batch . '. We recommend using Batch Number 0 so that it becomes the "first" migration', 0);
}
$this->info("Setting up Tables and Index Migrations");
$this->datePrefix = date('Y_m_d_His');
$this->generate('create', $tables);
$this->info("\nSetting up Foreign Key Migrations\n");
$this->datePrefix = date('Y_m_d_His', strtotime('+1 second'));
$this->generate('foreign_keys', $tables);
$this->info("\nFinished!\n");
}