Support altering indexes

Signed-off-by: Takashi SHIRAI <shirai@nintendo.co.jp>
This commit is contained in:
Takashi SHIRAI 2019-03-26 13:53:54 +09:00 committed by Jakub Vrana
parent 98458f737d
commit ef53494df0
2 changed files with 33 additions and 0 deletions

View file

@ -370,6 +370,38 @@ ORDER BY ac.constraint_type, aic.column_position", $connection2) as $row) {
;
}
function alter_indexes($table, $alter) {
$create = array();
$drop = array();
$queries = array();
foreach ($alter as $val) {
$val[2] = preg_replace('~ DESC$~', '', $val[2]);
if ($val[0] != "INDEX") {
//! descending UNIQUE indexes results in syntax error
$create[] = ($val[2] == "DROP"
? "\nDROP CONSTRAINT " . idf_escape($val[1])
: "\nADD" . ($val[1] != "" ? " CONSTRAINT " . idf_escape($val[1]) : "") . " $val[0] " . ($val[0] == "PRIMARY" ? "KEY " : "") . "(" . implode(", ", $val[2]) . ")"
);
} elseif ($val[2] == "DROP") {
$drop[] = idf_escape($val[1]);
} else {
$queries[] = "CREATE INDEX " . idf_escape($val[1] != "" ? $val[1] : uniqid($table . "_")) . " ON " . table($table) . " (" . implode(", ", $val[2]) . ")";
}
}
if ($create) {
array_unshift($queries, "ALTER TABLE " . table($table) . implode(",", $create));
}
if ($drop) {
array_unshift($queries, "DROP INDEX " . implode(", ", $drop));
}
foreach ($queries as $query) {
if (!queries($query)) {
return false;
}
}
return true;
}
function foreign_keys($table) {
$return = array();
$query = "SELECT c_list.CONSTRAINT_NAME as NAME,

View file

@ -10,6 +10,7 @@ PostgreSQL: Avoid exporting empty sequence last value (bug #768)
PostgreSQL: Do not show triggers from other schemas (PR #412)
PostgreSQL: Fix multi-parameter functions in default values (bug #736)
PostgreSQL PDO: Do not select NULL function for false values in edit
Oracle: Alter indexes
Oracle: Count tables
Oracle: Import from CSV
Oracle: Fix column size with string type