Esempio n. 1
0
 /**
  * Convert an index description results into schema indexes or constraints.
  *
  * @param TableSchema $table The table object to append
  *    an index or constraint to.
  * @param array $row The row data from `describeIndexSql`.
  * @return void
  */
 public function convertIndexDescription(TableSchema $table, $row)
 {
     $type = null;
     $columns = $length = [];
     $name = $row['Key_name'];
     if ($name === 'PRIMARY') {
         $name = $type = TableSchema::CONSTRAINT_PRIMARY;
     }
     $columns[] = $row['Column_name'];
     if ($row['Index_type'] === 'FULLTEXT') {
         $type = TableSchema::INDEX_FULLTEXT;
     } elseif ($row['Non_unique'] == 0 && $type !== 'primary') {
         $type = TableSchema::CONSTRAINT_UNIQUE;
     } elseif ($type !== 'primary') {
         $type = TableSchema::INDEX_INDEX;
     }
     if (!empty($row['Sub_part'])) {
         $length[$row['Column_name']] = $row['Sub_part'];
     }
     $isIndex = $type === TableSchema::INDEX_INDEX || $type === TableSchema::INDEX_FULLTEXT;
     if ($isIndex) {
         $existing = $table->index($name);
     } else {
         $existing = $table->constraint($name);
     }
     // MySQL multi column indexes come back as multiple rows.
     if (!empty($existing)) {
         $columns = array_merge($existing['columns'], $columns);
         $length = array_merge($existing['length'], $length);
     }
     if ($isIndex) {
         $table->addIndex($name, ['type' => $type, 'columns' => $columns, 'length' => $length]);
     } else {
         $table->addConstraint($name, ['type' => $type, 'columns' => $columns, 'length' => $length]);
     }
 }
Esempio n. 2
0
 /**
  * Convert an index description results into schema indexes or constraints.
  *
  * @param TableSchema $table The table object to append
  *    an index or constraint to.
  * @param array $row The row data from `describeIndexSql`.
  * @return void
  */
 public function convertIndexDescription(TableSchema $table, $row)
 {
     $type = TableSchema::INDEX_INDEX;
     $name = $row['index_name'];
     if ($row['is_primary_key']) {
         $name = $type = TableSchema::CONSTRAINT_PRIMARY;
     }
     if ($row['is_unique_constraint'] && $type === TableSchema::INDEX_INDEX) {
         $type = TableSchema::CONSTRAINT_UNIQUE;
     }
     if ($type === TableSchema::INDEX_INDEX) {
         $existing = $table->index($name);
     } else {
         $existing = $table->constraint($name);
     }
     $columns = [$row['column_name']];
     if (!empty($existing)) {
         $columns = array_merge($existing['columns'], $columns);
     }
     if ($type === TableSchema::CONSTRAINT_PRIMARY || $type === TableSchema::CONSTRAINT_UNIQUE) {
         $table->addConstraint($name, ['type' => $type, 'columns' => $columns]);
         return;
     }
     $table->addIndex($name, ['type' => $type, 'columns' => $columns]);
 }
Esempio n. 3
0
 /**
  * Convert an index description results into schema indexes or constraints.
  *
  * @param TableSchema $table The table object to append
  *    an index or constraint to.
  * @param array $row The row data from `describeIndexSql`.
  * @return void
  */
 public function convertIndexDescription(TableSchema $table, $row)
 {
     $sql = sprintf('PRAGMA index_info(%s)', $this->_driver->quoteIdentifier($row['name']));
     $statement = $this->_driver->prepare($sql);
     $statement->execute();
     $columns = [];
     foreach ($statement->fetchAll('assoc') as $column) {
         $columns[] = $column['name'];
     }
     $statement->closeCursor();
     if ($row['unique']) {
         $table->addConstraint($row['name'], ['type' => TableSchema::CONSTRAINT_UNIQUE, 'columns' => $columns]);
     } else {
         $table->addIndex($row['name'], ['type' => TableSchema::INDEX_INDEX, 'columns' => $columns]);
     }
 }