Created
October 25, 2012 22:34
-
-
Save eMerzh/3955908 to your computer and use it in GitHub Desktop.
Patch For MDB2 schema migration with PG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/3rdparty/MDB2/Driver/Manager/pgsql.php b/3rdparty/MDB2/Driver/Manager/pgsql.php | |
index f2c2137..3e70f3a 100644 | |
--- a/3rdparty/MDB2/Driver/Manager/pgsql.php | |
+++ b/3rdparty/MDB2/Driver/Manager/pgsql.php | |
@@ -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)) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment