/**
  * Generate Migrations
  *
  * @param  string $method Create Tables or Foreign Keys ['create', 'foreign_keys']
  * @param  array  $tables List of tables to create migrations for
  * @throws MethodNotFoundException
  * @return void
  */
 protected function generate($method, $tables)
 {
     if ($method == 'create') {
         $function = 'getFields';
         $prefix = 'create';
     } elseif ($method = 'foreign_keys') {
         $function = 'getForeignKeyConstraints';
         $prefix = 'add_foreign_keys_to';
         $method = 'table';
     } else {
         throw new MethodNotFoundException($method);
     }
     foreach ($tables as $table) {
         $this->migrationName = $prefix . '_' . $table . '_table';
         $this->method = $method;
         $this->table = $table;
         $this->fields = $this->schemaGenerator->{$function}($table);
         if ($this->fields) {
             parent::fire();
             if ($this->log) {
                 $file = $this->datePrefix . '_' . $this->migrationName;
                 $this->repository->log($file, $this->batch);
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Run "up" a migration instance.
  *
  * @param  string  $file
  * @param  int     $batch
  * @param  bool    $pretend
  * @return void
  */
 protected function runUp($file, $batch, $pretend)
 {
     // First we will resolve a "real" instance of the migration class from this
     // migration file name. Once we have the instances we can run the actual
     // command such as "up" or "down", or we can just simulate the action.
     $migration = $this->resolve($file);
     if ($pretend) {
         return $this->pretendToRun($migration, 'up');
     }
     $migration->up();
     // Once we have run a migrations class, we will log that it was run in this
     // repository so that we don't try to run it next time we do a migration
     // in the application. A migration repository keeps the migrate order.
     $this->repository->log($file, $batch);
     $this->note("<info>Migrated:</info> {$file}");
 }