summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/pgsqlschema.php31
1 files changed, 18 insertions, 13 deletions
diff --git a/lib/pgsqlschema.php b/lib/pgsqlschema.php
index 715065d77..7594edc8e 100644
--- a/lib/pgsqlschema.php
+++ b/lib/pgsqlschema.php
@@ -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,7 @@ class PgsqlSchema extends Schema
}
$sql = 'ALTER TABLE ' . $tableName . ' ' . implode(', ', $phrase);
-
+ echo "<p>$sql</p>";
$res = $this->conn->query($sql);
if (PEAR::isError($res)) {
@@ -496,12 +496,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 +522,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} ";