]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/pgsqlschema.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / lib / pgsqlschema.php
index a4ebafae4bc2505dc397f117c90a0f1c99e6b1f1..715065d774b977f5018a92f90955c00744e050ea 100644 (file)
@@ -1,4 +1,3 @@
-
 <?php
 /**
  * StatusNet, the distributed open-source microblogging tool
@@ -171,12 +170,10 @@ class PgsqlSchema extends Schema
         }
 
         if (count($primary) > 0) { // it really should be...
-            $sql .= ",\nconstraint primary key (" . implode(',', $primary) . ")";
+            $sql .= ",\n primary key (" . implode(',', $primary) . ")";
         }
 
-        foreach ($uniques as $u) {
-            $sql .= ",\nunique index {$name}_{$u}_idx ($u)";
-        }
+
 
         foreach ($indices as $i) {
             $sql .= ",\nindex {$name}_{$i}_idx ($i)";
@@ -184,6 +181,10 @@ class PgsqlSchema extends Schema
 
         $sql .= "); ";
 
+
+        foreach ($uniques as $u) {
+            $sql .= "\n CREATE index {$name}_{$u}_idx ON {$name} ($u); ";
+        }
         $res = $this->conn->query($sql);
 
         if (PEAR::isError($res)) {
@@ -214,6 +215,22 @@ class PgsqlSchema extends Schema
         return true;
     }
 
+    /**
+     * Translate the (mostly) mysql-ish column types into somethings more standard
+     * @param string column type
+     *
+     * @return string postgres happy column type
+     */
+    private function _columnTypeTranslation($type) {
+      $map = array(
+      'datetime' => 'timestamp'
+      );
+      if(!empty($map[$type])) {
+        return $map[$type];
+      }
+      return $type;
+    }
+
     /**
      * Adds an index to a table.
      *
@@ -483,11 +500,12 @@ class PgsqlSchema extends Schema
     private function _columnSql($cd)
     {
         $sql = "{$cd->name} ";
+        $type = $this->_columnTypeTranslation($cd->type);
 
         if (!empty($cd->size)) {
-            $sql .= "{$cd->type}({$cd->size}) ";
+            $sql .= "{$type}({$cd->size}) ";
         } else {
-            $sql .= "{$cd->type} ";
+            $sql .= "{$type} ";
         }
 
         if (!empty($cd->default)) {