protected function processIndexes() { /** @var Index[] $beforeIndexes */ $beforeIndexes = array(); foreach ($this->before->indexes as $index) { $beforeIndexes[$index->getName()] = $index; } foreach ($this->after->indexes as $index) { if (!isset($beforeIndexes[$index->getName()])) { $this->alterLines->commaExpr('ADD ' . ($index->type === Index::TYPE_UNIQUE ? 'UNIQUE ' : '') . 'INDEX ? (?)', new Symbol($index->getName()), Symbol::prepareColumns($index->columns)); } else { unset($beforeIndexes[$index->getName()]); } } if ($beforeIndexes) { foreach ($this->after->getForeignKeys() as $foreignKey) { if (isset($beforeIndexes[$foreignKey->getName()])) { unset($beforeIndexes[$foreignKey->getName()]); } } foreach ($beforeIndexes as $index) { $this->alterLines->commaExpr('DROP INDEX ?', new Symbol($index->getName())); } } }
protected function appendIndexes() { foreach ($this->table->indexes as $index) { $columns = Symbol::prepareColumns($index->columns); if ($index->type === Index::TYPE_KEY) { $this->createLines->commaExpr(' KEY ? (?)', new Symbol($index->getName()), $columns); } elseif ($index->type === Index::TYPE_UNIQUE) { $this->createLines->commaExpr(' UNIQUE KEY ? (?)', new Symbol($index->getName()), $columns); } } }
protected function appendIndexes() { foreach ($this->table->indexes as $index) { $columns = Symbol::prepareColumns($index->columns); if ($index->type === Index::TYPE_KEY) { $createIndex = new SimpleExpression("CREATE INDEX ? ON ? (?)", new Symbol($index->getName()), new Symbol($this->table->schemaName), $columns); $createIndex->bindDatabase($this->database()); $this->add($createIndex); //$this->appendExpr(' KEY ? (?),' . PHP_EOL, new Symbol($index->getName()), $columns); } elseif ($index->type === Index::TYPE_UNIQUE) { $this->createLines->commaExpr(' CONSTRAINT ? UNIQUE (?)', new Symbol($index->getName()), $columns); } } }
protected function processIndexes() { /** @var Index[] $beforeIndexes */ $beforeIndexes = array(); foreach ($this->before->indexes as $index) { $beforeIndexes[$index->getName()] = $index; } foreach ($this->after->indexes as $index) { $indexName = $index->getName(); if (!isset($beforeIndexes[$indexName])) { $this->add($this->database()->expr('CREATE ' . ($index->type === Index::TYPE_UNIQUE ? 'UNIQUE ' : '') . 'INDEX ? ON ? (?)', new Symbol($index->getName()), new Symbol($this->before->schemaName), Symbol::prepareColumns($index->columns))); } else { unset($beforeIndexes[$indexName]); } } foreach ($beforeIndexes as $index) { if ($index->type === Index::TYPE_UNIQUE) { $this->alterLines->commaExpr('DROP CONSTRAINT ?', new Symbol($index->getName())); } else { $this->add($this->database()->expr('DROP INDEX ?', new Symbol($index->getName()))); } } }
public function generateForeignKeyExpression(Database\Definition\ForeignKey $foreignKey) { return new SimpleExpression(' CONSTRAINT ? FOREIGN KEY (?) REFERENCES ? (?)??', new Symbol($foreignKey->getName()), Symbol::prepareColumns($foreignKey->getLocalColumns()), new Symbol($foreignKey->getReferencedTable()->schemaName), Symbol::prepareColumns($foreignKey->getReferenceColumns()), new Raw($foreignKey->onUpdate === ForeignKey::NO_ACTION ? '' : ' ON UPDATE ' . $foreignKey->onUpdate), new Raw($foreignKey->onDelete === ForeignKey::NO_ACTION ? '' : ' ON DELETE ' . $foreignKey->onDelete)); }