/** * @param string $table * @param \Doctrine\DBAL\Schema\Index $index * @return array */ protected function indexToArray($table, $index) { if ($index->isPrimary()) { $type = 'primary'; } elseif ($index->isUnique()) { $type = 'unique'; } else { $type = 'index'; } $array = ['type' => $type, 'name' => null, 'columns' => $index->getColumns()]; if (!$this->isDefaultIndexName($table, $index->getName(), $type, $index->getColumns())) { $array['name'] = $index->getName(); } return $array; }
/** * @param string $table * @param \Doctrine\DBAL\Schema\Index $index * @return array */ protected function indexToArray($table, $index) { if ($index->isPrimary()) { $type = 'primary'; } elseif ($index->isUnique()) { $type = 'unique'; } else { $type = 'index'; } $array = ['type' => $type, 'name' => null, 'columns' => $index->getColumns()]; if (!$this->ignoreIndexNames and !$this->isDefaultIndexName($table, $index->getName(), $type, $index->getColumns())) { // Sent Index name to exclude spaces $array['name'] = str_replace(' ', '', $index->getName()); } return $array; }
/** * Add index to table * * @param Index $indexCandidate * @return Table */ protected function _addIndex(Index $indexCandidate) { // check for duplicates foreach ($this->_indexes as $existingIndex) { if ($indexCandidate->isFullfilledBy($existingIndex)) { return $this; } } $indexName = $indexCandidate->getName(); $indexName = strtolower($indexName); if (isset($this->_indexes[$indexName]) || $this->_primaryKeyName != false && $indexCandidate->isPrimary()) { throw SchemaException::indexAlreadyExists($indexName, $this->_name); } // remove overruled indexes foreach ($this->_indexes as $idxKey => $existingIndex) { if ($indexCandidate->overrules($existingIndex)) { unset($this->_indexes[$idxKey]); } } if ($indexCandidate->isPrimary()) { $this->_primaryKeyName = $indexName; } $this->_indexes[$indexName] = $indexCandidate; return $this; }
/** * Drop and create a new index on a table * * @param string|Table $table name of the table on which the index is to be created * @param Index $index */ public function dropAndCreateIndex(Index $index, $table) { $this->tryMethod('dropIndex', $index->getName(), $table); $this->createIndex($index, $table); }
/** * Do checks for indexes. * * @param Index $index * @param IgnoredChange $ignoredChange * * @return boolean */ protected function checkIndex(Index $index, IgnoredChange $ignoredChange) { // Not needed to be implemented yet if ($ignoredChange->getPropertyName() !== $index->getName()) { return false; } return false; }
/** * Do checks for indexes. * * @param Index $index * @param array $alterData * * @return boolean */ protected function checkIndex(Index $index, array $alterData) { // Not needed to be implemented yet if ($alterData['propertyName'] !== $index->getName()) { return false; } return false; }
/** * Gets the SQL to create an index on a table on this platform. * * @param Index $index * @param string|Table $table name of the table on which the index is to be created * @return string */ public function getCreateIndexSQL(Index $index, $table) { if ($table instanceof Table) { $table = $table->getName(); } $name = $index->getName(); $columns = $index->getColumns(); if (count($columns) == 0) { throw new \InvalidArgumentException("Incomplete definition. 'columns' required."); } $type = ''; if ($index->isUnique()) { $type = 'UNIQUE '; } $query = 'CREATE ' . $type . 'INDEX ' . $name . ' ON ' . $table; $query .= ' (' . $this->getIndexFieldDeclarationListSQL($columns) . ')'; return $query; }
/** * Adds an index to the table. * * @param Index $indexCandidate * * @return self * * @throws SchemaException */ protected function _addIndex(Index $indexCandidate) { $indexName = $indexCandidate->getName(); $indexName = $this->normalizeIdentifier($indexName); $replacedImplicitIndexes = array(); foreach ($this->implicitIndexes as $name => $implicitIndex) { if ($implicitIndex->isFullfilledBy($indexCandidate) && isset($this->_indexes[$name])) { $replacedImplicitIndexes[] = $name; } } if (isset($this->_indexes[$indexName]) && !in_array($indexName, $replacedImplicitIndexes, true) || $this->_primaryKeyName != false && $indexCandidate->isPrimary()) { throw SchemaException::indexAlreadyExists($indexName, $this->_name); } foreach ($replacedImplicitIndexes as $name) { unset($this->_indexes[$name], $this->implicitIndexes[$name]); } if ($indexCandidate->isPrimary()) { $this->_primaryKeyName = $indexName; } $this->_indexes[$indexName] = $indexCandidate; return $this; }
/** * @param Index $index * @param \SimpleXMLElement $xml */ private static function saveIndex($index, $xml) { $xml->addChild('name', $index->getName()); if ($index->isPrimary()) { $xml->addChild('primary', 'true'); } elseif ($index->isUnique()) { $xml->addChild('unique', 'true'); } foreach ($index->getColumns() as $column) { $field = $xml->addChild('field'); $field->addChild('name', $column); $field->addChild('sorting', 'ascending'); } }
/** * Creates a index replacement, which has quoted names. * * @param Index $index * * @return Index */ private function createIndexReplacement(Index $index) { return new Index($this->platform->quoteIdentifier($index->getName()), $this->quoteIdentifiers($index->getColumns()), $index->isUnique(), $index->isPrimary(), $index->getFlags(), $index->getOptions()); }
/** * {@inheritDoc} */ public function getCreatePrimaryKeySQL(Index $index, $table) { $sql = 'ALTER TABLE ' . $table . ' ADD CONSTRAINT PRIMARY KEY (' . $this->getIndexFieldDeclarationListSQL($index->getQuotedColumns($this)) . ')'; if ($index->getName()) { $sql .= ' CONSTRAINT ' . $index->getQuotedName($this); } return $sql; }
/** * Accept an index on in a table * * @param Table $table a table object * @param Index $index a column object * * @return void */ public function acceptIndex(Table $table, Index $index) { $this->schemaArray['tables'][$table->getName()]['indexes'][$index->getName()] = array('name' => $index->getName(), 'columns' => $index->getColumns(), 'unique' => $index->isUnique(), 'primary' => $index->isPrimary()); }