]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix migration problems for postgresql with MDB2 fix owncloud/apps#21
authorBrice Maron <brice@bmaron.net>
Fri, 26 Oct 2012 15:54:16 +0000 (15:54 +0000)
committerBrice Maron <brice@bmaron.net>
Fri, 26 Oct 2012 15:56:53 +0000 (15:56 +0000)
Ref of MDB2 bug is 19676

3rdparty/MDB2/Driver/Manager/pgsql.php

index f2c2137dc8b3b1c6c536392b5dd26eb229a55060..3e70f3a3b252ff75b726b7b3bee9c8c1a2539a3e 100644 (file)
@@ -363,6 +363,7 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
             return MDB2_OK;
         }
 
+        $unquoted_name = $name;
         $name = $db->quoteIdentifier($name, true);
 
         if (!empty($changes['remove']) && is_array($changes['remove'])) {
@@ -398,6 +399,7 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
 
         if (!empty($changes['change']) && is_array($changes['change'])) {
             foreach ($changes['change'] as $field_name => $field) {
+                $unquoted_field_name = $field_name;
                 $field_name = $db->quoteIdentifier($field_name, true);
                 if (!empty($field['definition']['type'])) {
                     $server_info = $db->getServerVersion();
@@ -419,7 +421,14 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
                         return $result;
                     }
                 }
-                if (array_key_exists('default', $field['definition'])) {
+                if (array_key_exists('autoincrement', $field['definition'])) {
+                    $query = "ALTER $field_name SET DEFAULT nextval(".$db->quote($unquoted_name.'_'.$unquoted_field_name.'_seq', 'text').")";
+                    $result = $db->exec("ALTER TABLE $name $query");
+                    if (PEAR::isError($result)) {
+                        return $result;
+                    }
+                }
+                elseif (array_key_exists('default', $field['definition'])) {
                     $query = "ALTER $field_name SET DEFAULT ".$db->quote($field['definition']['default'], $field['definition']['type']);
                     $result = $db->exec("ALTER TABLE $name $query");
                     if (PEAR::isError($result)) {