Fixed a PostgreSQL issue
authorMarcel Werk <burntime@woltlab.com>
Thu, 5 Jan 2012 15:46:57 +0000 (16:46 +0100)
committerMarcel Werk <burntime@woltlab.com>
Thu, 5 Jan 2012 15:46:57 +0000 (16:46 +0100)
wcfsetup/install/files/lib/system/database/editor/PostgreSQLDatabaseEditor.class.php

index eb8fcaf0eb97059155187963175890cdb63e375f..18eeea23d4deb0b92b0dc88b06be92efcd98b93d 100644 (file)
@@ -223,8 +223,15 @@ class PostgreSQLDatabaseEditor extends DatabaseEditor {
                $columns = ArrayUtil::trim(explode(',', $indexData['columns']));
                if (empty($indexName)) {
                        // create index name
-                       // TODO: solve naming conflicts
                        $indexName = $tableName.'_'.(!empty($columns[0]) ? $columns[0] : 'generic').'_key';
+                       
+                       // solve naming conflicts
+                       $indices = $this->getIndices($tableName);
+                       $i = 2;
+                       while (in_array($indexName, $indices)) {
+                               $indexName = $tableName.'_'.(!empty($columns[0]) ? $columns[0] : 'generic').'_'.$i.'_key';
+                               $i++;
+                       }
                }
                else {
                        $indexName = $tableName.'_'.$indexName.'_key';