/** * 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"); }
/** * Create a list of columns available on the given table's translation table. * * @param string $table * * @return array */ private function setTranslatable($table) { $translate_table = $this->getTranslationTable($table); $translatable = []; // get a list of columns $columns = $this->schemaGenerator->getSchema()->listTableColumns($translate_table); // exclude the globally excluded field + primary key(s) $excluded = $this->excludedFieldsForTable($translate_table); foreach ($columns as $column) { if (!in_array($column->getName(), $excluded)) { $translatable[] = $column->getName(); } } return $translatable; }
/** * 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'); } } }