/** * Get table list from command option. * * @return array */ protected function getExistingTables() { $tables = $this->option('tables'); $tables = !is_null($tables) ? $this->splitOptions($tables) : []; $tablesFromDb = $this->schema->getTables(); return !empty($tables) ? array_intersect($tablesFromDb, $tables) : $tablesFromDb; }
/** * Get relationship other or local key. * * @param string $table * @param string $otherKey * @return null */ protected function getRelationshipOtherKey($table, $otherKey) { // In order to push necessary value to the relationships functions // we have to find the value of the other/local key that is used // to join two tables. If it's like primary key, we will skip it. $pk = $this->schema->getPrimaryKey($table); return is_null($pk) || $pk != $otherKey ? $otherKey : null; }
/** * 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; }