Esempio n. 1
0
 /**
  * Process table to get migrations fields.
  *
  * @param string $table
  * @return array
  */
 public function process($table)
 {
     $this->migrationRows = [];
     $primaryKey = $this->schema->getPrimaryKey($table);
     $foreign = $this->schema->getForeign($table);
     $indexes = $this->schema->getIndexes($table);
     $timestamps = $this->schema->getTimestamps($table);
     $laravelTimestamps = $this->hasLaravelTimestamps($timestamps);
     foreach ($this->schema->getColumns($table) as $column) {
         $name = $column->getName();
         // If you have default timestamps in the special order in your table we
         // will check their names while processing in order not parsing them
         // as default timestamp field with our grammar instance.
         if ($laravelTimestamps && in_array($name, $this->timestamps)) {
             continue;
         }
         $status = $this->processRow($column, $name == $primaryKey, in_array($name, $indexes['unique']));
         if ($status) {
             $this->processForeign($column, $foreign);
         }
     }
     // If we have default laravel timestamps in the table we will generate
     // the necessary migration row.
     $this->processTimestamps($laravelTimestamps);
     //$this->processIndexes($indexes['index']);
     $this->processIndexesWithoutForeigns($indexes['index'], array_keys($foreign));
     return $this->migrationRows;
 }
Esempio n. 2
0
 /**
  * Get all the fields from pivot table.
  *
  * @param array $foreignKeys
  * @param string $table
  * @return array
  */
 protected function getFieldsFromPivotTable($foreignKeys, $table)
 {
     // In order to get only appropriate fields from pivot table
     // it's necessary to create a list of columns that doesn't
     // consists of primary key, Eloquent timestamp fields.
     $pk = $this->schema->getPrimaryKey($table);
     if (!is_null($pk)) {
         $foreignKeys[] = $pk;
     }
     if ($this->compiled[$table]['timestamps']) {
         $foreignKeys = array_merge($foreignKeys, $this->timestamps);
     }
     return array_diff(array_keys($this->schema->getColumns($table)), $foreignKeys);
 }