summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-02-23 18:46:21 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-02-23 18:46:21 +0000
commitbd4809c9c5920b90d2b57c590c16ccb093f2201a (patch)
tree509c867784e81859a3272a9d37e9cd73f768d614
parentdce608f5a4a33fb679c266c926efdaf4a084ba86 (diff)
downloadbrdo-bd4809c9c5920b90d2b57c590c16ccb093f2201a.tar.gz
brdo-bd4809c9c5920b90d2b57c590c16ccb093f2201a.tar.bz2
#718016 by andypost and Damien Tournoud: Fixed DatabaseSchema_pgsql()::renameTable() needs to rename the indexes.
-rw-r--r--includes/database/pgsql/schema.inc15
1 files changed, 15 insertions, 0 deletions
diff --git a/includes/database/pgsql/schema.inc b/includes/database/pgsql/schema.inc
index f36ae2c32..0ee2d6f14 100644
--- a/includes/database/pgsql/schema.inc
+++ b/includes/database/pgsql/schema.inc
@@ -276,6 +276,21 @@ class DatabaseSchema_pgsql extends DatabaseSchema {
}
function renameTable($table, $new_name) {
+ // Get the schema and tablename for the old table.
+ $old_full_name = $this->connection->prefixTables('{' . $table . '}');
+ list($old_schema, $old_table_name) = strpos($old_full_name, '.') ? explode('.', $old_full_name) : array('public', $old_full_name);
+
+ // Index names and constraint names are global in PostgreSQL, so we need to
+ // rename them when renaming the table.
+ $indexes = $this->connection->query('SELECT indexname FROM pg_indexes WHERE schemaname = :schema AND tablename = :table', array(':schema' => $old_schema, ':table' => $old_table_name));
+ foreach ($indexes as $index) {
+ if (preg_match('/^' . preg_quote($old_full_name) . '_(.*)_idx$/', $index->indexname, $matches)) {
+ $index_name = $matches[1];
+ $this->connection->query('ALTER INDEX ' . $index->indexname . ' RENAME TO {' . $new_name . '}_' . $index_name . '_idx');
+ }
+ }
+
+ // Now rename the table.
$this->connection->query('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}');
}