]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/pgsqlschema.php
removed sneaky debug echo that shouldn't be there
[quix0rs-gnu-social.git] / lib / pgsqlschema.php
index 715065d774b977f5018a92f90955c00744e050ea..12f24cfbe119550183e76340550419fe8e9623c5 100644 (file)
@@ -41,6 +41,7 @@ if (!defined('STATUSNET')) {
  * @category Database
  * @package  StatusNet
  * @author   Evan Prodromou <evan@status.net>
+ * @author   Brenda Wallace <shiny@cpan.org>
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link     http://status.net/
  */
@@ -79,7 +80,6 @@ class PgsqlSchema extends Schema
         $row = array();
 
         while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) {
-//             var_dump($row);
             $cd = new ColumnDef();
 
             $cd->name = $row['field'];
@@ -155,7 +155,6 @@ class PgsqlSchema extends Schema
             }
 
             $sql .= $this->_columnSql($cd);
-
             switch ($cd->key) {
             case 'UNI':
                 $uniques[] = $cd->name;
@@ -188,7 +187,7 @@ class PgsqlSchema extends Schema
         $res = $this->conn->query($sql);
 
         if (PEAR::isError($res)) {
-            throw new Exception($res->getMessage());
+            throw new Exception($res->getMessage(). ' SQL was '. $sql);
         }
 
         return true;
@@ -223,7 +222,7 @@ class PgsqlSchema extends Schema
      */
     private function _columnTypeTranslation($type) {
       $map = array(
-      'datetime' => 'timestamp'
+      'datetime' => 'timestamp',
       );
       if(!empty($map[$type])) {
         return $map[$type];
@@ -397,16 +396,17 @@ class PgsqlSchema extends Schema
         $todrop = array_diff($cur, $new);
         $same   = array_intersect($new, $cur);
         $tomod  = array();
-
         foreach ($same as $m) {
             $curCol = $this->_byName($td->columns, $m);
             $newCol = $this->_byName($columns, $m);
+            
 
             if (!$newCol->equals($curCol)) {
-                $tomod[] = $newCol->name;
+            // BIG GIANT TODO!
+            // stop it detecting different types and trying to modify on every page request
+//                 $tomod[] = $newCol->name;
             }
         }
-
         if (count($toadd) + count($todrop) + count($tomod) == 0) {
             // nothing to do
             return true;
@@ -434,7 +434,6 @@ class PgsqlSchema extends Schema
         }
 
         $sql = 'ALTER TABLE ' . $tableName . ' ' . implode(', ', $phrase);
-
         $res = $this->conn->query($sql);
 
         if (PEAR::isError($res)) {
@@ -496,12 +495,21 @@ class PgsqlSchema extends Schema
      *
      * @return string correct SQL for that column
      */
-
     private function _columnSql($cd)
     {
         $sql = "{$cd->name} ";
         $type = $this->_columnTypeTranslation($cd->type);
 
+        //handle those mysql enum fields that postgres doesn't support
+        if (preg_match('!^enum!', $type)) {
+          $allowed_values = preg_replace('!^enum!', '', $type);
+          $sql .= " text check ({$cd->name} in $allowed_values)";
+          return $sql;
+        }
+        if (!empty($cd->auto_increment)) {
+          $type = 'serial';
+        }
+
         if (!empty($cd->size)) {
             $sql .= "{$type}({$cd->size}) ";
         } else {
@@ -513,10 +521,6 @@ class PgsqlSchema extends Schema
         } else {
             $sql .= ($cd->nullable) ? "null " : "not null ";
         }
-        
-        if (!empty($cd->auto_increment)) {
-            $sql .= " auto_increment ";
-        }
 
         if (!empty($cd->extra)) {
             $sql .= "{$cd->extra} ";