/** * 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"); }
/** * Retrieve the translation table for a given table, false if not found. * * @param string $table * * @return string|bool */ private function getTranslationTable($table) { // the check should not be executed for a translation table if (preg_match('/_translations$/', $table)) { return false; } // list all the tables $tables = $this->schemaGenerator->getTables(); $singular = str_singular($table) . '_translations'; $plural = str_plural($table) . '_translations'; // check if the translation tables exists foreach ($tables as $table_name) { if ($table_name == $singular || $table_name == $plural) { return $table_name; } } return false; }
/** * Execute the command. * * @return void */ public function handle() { /* $this->commandData->modelName = $this->argument('model'); $this->commandData->initVariables(); $this->commandData->inputFields = $this->getInputFields(); */ $followRepoPattern = $this->confirm("\nDo you want to generate repository ? (y|N)", false); /* $migrationGenerator = new MigrationGenerator($this->commandData); $migrationGenerator->generate(); */ $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"); //do rest if (is_array($tables)) { foreach ($tables as $table) { $this->commandData = new CommandData($this); $this->commandData->modelName = $table; $this->commandData->initVariables(); $this->commandData->inputFields = $this->getInputFields($table); $modelGenerator = new ModelGenerator($this->commandData); $modelGenerator->generate(); if ($followRepoPattern) { $repositoryGenerator = new RepositoryGenerator($this->commandData); $repositoryGenerator->generate(); $repoControllerGenerator = new RepoAPIControllerGenerator($this->commandData); $repoControllerGenerator->generate(); } else { $controllerGenerator = new APIControllerGenerator($this->commandData); $controllerGenerator->generate(); } $routeGenerator = new RoutesGenerator($this->commandData); $routeGenerator->generate(); //if($this->confirm("\nDo you want to migrate database? [y|N]", false)) //$this->call('migrate'); } } }