/** * 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; }
/** * Compile relationships. * * @param string $table * @return void */ protected function compileRelationships($table) { $foreign = $this->schema->getForeign($table); $indexes = $this->schema->getIndexes($table); if (!empty($foreign)) { if (count($foreign) == 1) { $foreignColumnName = key($foreign); $isUnique = in_array($foreignColumnName, $indexes['unique']); $this->compileOneToRelationship(reset($foreign), $foreignColumnName, $isUnique, $table); } else { $this->compileManyToRelationship($foreign, $table); } } }