/**
  * 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");
 }
Ejemplo n.º 2
0
 /**
  * Creates a new database schema.
  * 
  * @param  string $schemaName
  * @return bool
  */
 public function createSchema($schemaName)
 {
     $schema = $this->schemaDriver->createSchema($schemaName);
     $this->repository->setSource($schemaName);
     $this->repository->createRepository();
     return $schema;
 }
Ejemplo n.º 3
0
 /**
  * Set the default connection name.
  *
  * @param  string  $name
  * @return void
  */
 public function setConnection($name)
 {
     if (!is_null($name)) {
         $this->resolver->setDefaultConnection($name);
     }
     $this->repository->setSource($name);
     $this->connection = $name;
 }
Ejemplo n.º 4
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $this->repository->setSource($this->input->getOption('database'));
     $this->repository->createRepository();
     $this->info("Migration table created successfully.");
 }
 /**
  * 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');
         }
     }
 }