/** * Rename an index from an existing table * * @param string $table Name of the table to modify * @param string $oldIndex Old name of the index * @param string $newIndex New name of the index * @param bool $skipBothIndexExistWarning Whether to warn if both the * old and the new indexes exist. * @param string $patch Path to the patch file * @param bool $fullpath Whether to treat $patch path as a relative or not * @return bool False if this was skipped because schema changes are skipped */ protected function renameIndex($table, $oldIndex, $newIndex, $skipBothIndexExistWarning, $patch, $fullpath = false) { if (!$this->doTable($table)) { return true; } // First requirement: the table must exist if (!$this->db->tableExists($table, __METHOD__)) { $this->output("...skipping: '{$table}' table doesn't exist yet.\n"); return true; } // Second requirement: the new index must be missing if ($this->db->indexExists($table, $newIndex, __METHOD__)) { $this->output("...index {$newIndex} already set on {$table} table.\n"); if (!$skipBothIndexExistWarning && $this->db->indexExists($table, $oldIndex, __METHOD__)) { $this->output("...WARNING: {$oldIndex} still exists, despite it has " . "been renamed into {$newIndex} (which also exists).\n" . " {$oldIndex} should be manually removed if not needed anymore.\n"); } return true; } // Third requirement: the old index must exist if (!$this->db->indexExists($table, $oldIndex, __METHOD__)) { $this->output("...skipping: index {$oldIndex} doesn't exist.\n"); return true; } // Requirements have been satisfied, patch can be applied return $this->applyPatch($patch, $fullpath, "Renaming index {$oldIndex} into {$newIndex} to table {$table}"); }
/** * Drop an index from an existing table * * @param $table String: Name of the table to modify * @param $index String: Name of the old index * @param $patch String: Path to the patch file * @param $fullpath Boolean: Whether to treat $patch path as a relative or not */ protected function dropIndex($table, $index, $patch, $fullpath = false) { if ($this->db->indexExists($table, $index, __METHOD__)) { $this->applyPatch($patch, $fullpath, "Dropping {$index} index from table {$table}"); } else { $this->output("...{$index} key doesn't exist.\n"); } }
/** * (MySQL only) Drops fulltext index before populating the table. */ private function dropMysqlTextIndex() { $searchindex = $this->db->tableName('searchindex'); if ($this->db->indexExists('searchindex', 'si_title', __METHOD__)) { $this->output("Dropping index...\n"); $sql = "ALTER TABLE {$searchindex} DROP INDEX si_title, DROP INDEX si_text"; $this->db->query($sql, __METHOD__); } }