* @param array $indexData
*/
abstract public function addForeignKey($tableName, $indexName, $indexData);
-
+
/**
* Drops an existing index.
- *
+ *
* @param string $tableName
* @param string $indexName
*/
abstract public function dropIndex($tableName, $indexName);
+
+ /**
+ * Drops existing primary keys.
+ *
+ * @param string $tableName
+ */
+ abstract public function dropPrimaryKey($tableName);
/**
* Drops an existing foreign key.
$statement->execute();
}
+ /**
+ * @see \wcf\system\database\editor\DatabaseEditor::dropPrimaryKey()
+ */
+ public function dropPrimaryKey($tableName) {
+ $sql = "ALTER TABLE ".$tableName." DROP PRIMARY KEY";
+ $statement = $this->dbObj->prepareStatement($sql);
+ $statement->execute();
+ }
+
/**
* @see \wcf\system\database\editor\DatabaseEditor::dropForeignKey()
*/
$statement->execute();
}
+ /**
+ * @see \wcf\system\database\editor\DatabaseEditor::dropPrimaryKey()
+ */
+ public function dropPrimaryKey($tableName) {
+ $sql = "ALTER TABLE ".$tableName." DROP CONSTRAINT ".$indexName." CASCADE";
+ $statement = $this->dbObj->prepareStatement($sql);
+ $statement->execute();
+ }
+
/**
* @see \wcf\system\database\editor\DatabaseEditor::dropForeignKey()
*/
else if (preg_match('~^ALTER\s+TABLE\s+(\w+)\s+DROP\s+(?:INDEX|KEY)\s+(\w+)~is', $query, $match)) {
$this->executeDropIndexStatement($match[1], $match[2]);
}
+ // drop primary key
+ else if (preg_match('~^ALTER\s+TABLE\s+(\w+)\s+DROP\s+PRIMARY\s+KEY~is', $query, $match)) {
+ $this->executeDropPrimaryKeyStatement($match[1]);
+ }
// drop foreign key
else if (preg_match('~^ALTER\s+TABLE\s+(\w+)\s+DROP\s+FOREIGN KEY\s+(\w+)~is', $query, $match)) {
$this->executeDropForeignKeyStatement($match[1], self::getGenericIndexName($match[1], $match[2], 'fk'));
WCF::getDB()->getEditor()->dropIndex($tableName, $indexName);
}
+ /**
+ * Executes a 'DROP PRIMARY KEY' statement.
+ *
+ * @param string $tableName
+ * @param string $primaryKeyName
+ */
+ protected function executeDropPrimaryKeyStatement($tableName) {
+ WCF::getDB()->getEditor()->dropPrimaryKey($tableName);
+ }
+
/**
* Executes a 'DROP FOREIGN KEY' statement.
*
}
}
+ /**
+ * @see \wcf\system\database\util\SQLParser::executeDropPrimaryKeyStatement()
+ */
+ protected function executeDropPrimaryKeyStatement($tableName) {
+ if ($this->test) {
+ if ($ownerPackageID = $this->getIndexOwnerID($tableName, '')) {
+ if ($ownerPackageID != $this->package->packageID) {
+ throw new SystemException("Cannot drop primary key from '".$tableName."'. A package can only drop own indices.");
+ }
+ }
+ }
+ else {
+ // log
+ $this->indexLog[] = array('tableName' => $tableName, 'indexName' => '', 'packageID' => $this->package->packageID, 'action' => 'delete');
+
+ // execute
+ parent::executeDropPrimaryKeyStatement($tableName);
+ }
+ }
+
/**
* @see \wcf\system\database\util\SQLParser::executeDropForeignKeyStatement()
*/