Tylko w drupal-head-revisions/database: .updates.inc.swp
diff -rup drupal-head-revisions_43/database/updates.inc drupal-head-revisions/database/updates.inc
--- drupal-head-revisions_43/database/updates.inc	2005-08-28 23:28:01.000000000 +0200
+++ drupal-head-revisions/database/updates.inc	2005-08-28 23:55:23.000000000 +0200
@@ -713,51 +713,65 @@ function update_146() {
     $ret[] = update_sql("CREATE TABLE {node_revisions}
                                 SELECT nid, nid AS vid, uid, type, title, body, teaser, changed AS timestamp, format 
                                 FROM {node}");
+  }
+  else { // pgsql
+    $ret[] = update_sql("CREATE TABLE {node_revisions} AS
+                                SELECT nid, nid AS vid, uid, type, title, body, teaser, changed AS timestamp, format 
+                                FROM {node}");
+  }
 
+  if ($GLOBALS['db_type'] == 'mysql') {
     $ret[] = update_sql("ALTER TABLE {node_revisions} CHANGE nid nid int(10) unsigned NOT NULL default '0'");
-    $ret[] = update_sql("ALTER TABLE {node_revisions} ADD log longtext");
+  }
+  else { // pgsql
+    // TODO
+  }
+  db_add_column($ret, 'node_revisions', 'log', 'longtext');
+  
+  db_add_column($ret, 'node', 'vid', 'int', array('unsigned' => TRUE, 'not null' => TRUE, 'default' => '0'));
+  db_add_column($ret, 'files', 'vid', 'int', array('unsigned' => TRUE, 'not null' => TRUE, 'default' => '0'));
+  db_add_column($ret, 'book', 'vid', 'int', array('unsigned' => TRUE, 'not null' => TRUE, 'default' => '0'));
+  db_add_column($ret, 'forum', 'vid', 'int', array('unsigned' => TRUE, 'not null' => TRUE, 'default' => '0'));
+
+  db_drop_primary_key($ret, 'book');
+  db_drop_primary_key($ret, 'forum');
+  db_drop_primary_key($ret, 'files');
+
+  $ret[] = update_sql("UPDATE {node} SET vid = nid");
+  $ret[] = update_sql("UPDATE {forum} SET vid = nid");
+  $ret[] = update_sql("UPDATE {book} SET vid = nid");
+  $ret[] = update_sql("UPDATE {files} SET vid = nid");
+
+  db_add_primary_key($ret, 'book', 'vid');
+  db_add_primary_key($ret, 'forum', 'vid');
+  db_add_primary_key($ret, 'node_revisions', 'vid');
 
-    $ret[] = update_sql("ALTER TABLE {node} ADD vid int(10) unsigned NOT NULL default '0'");
-    $ret[] = update_sql("ALTER TABLE {files} ADD vid int(10) unsigned NOT NULL default '0'");
-    $ret[] = update_sql("ALTER TABLE {book} ADD vid int(10) unsigned NOT NULL default '0'");
-    $ret[] = update_sql("ALTER TABLE {forum} ADD vid int(10) unsigned NOT NULL default '0'");
-
-    $ret[] = update_sql("ALTER TABLE {book} DROP PRIMARY KEY");
-    $ret[] = update_sql("ALTER TABLE {forum} DROP PRIMARY KEY");
-    $ret[] = update_sql("ALTER TABLE {files} DROP PRIMARY KEY");
-
-    $ret[] = update_sql("UPDATE {node} SET vid = nid");
-    $ret[] = update_sql("UPDATE {forum} SET vid = nid");
-    $ret[] = update_sql("UPDATE {book} SET vid = nid");
-    $ret[] = update_sql("UPDATE {files} SET vid = nid");
-
-    $ret[] = update_sql("ALTER TABLE {book} ADD PRIMARY KEY vid (vid)");
-    $ret[] = update_sql("ALTER TABLE {forum} ADD PRIMARY KEY vid (vid)");
-    $ret[] = update_sql("ALTER TABLE {node_revisions} ADD PRIMARY KEY vid (vid)");
+  if ($GLOBALS['db_type'] == 'mysql') {
     $ret[] = update_sql("ALTER TABLE {node_revisions} ADD KEY nid (nid)");
     $ret[] = update_sql("ALTER TABLE {node_revisions} ADD KEY uid (uid)");
-
+  }
+  else { // pgsql
+    // TODO: IIRC KEY is the same as INDEX so only syntax is different then mysql's
+  }
+  
+  if ($GLOBALS['db_type'] == 'mysql') {
     $ret[] = update_sql("CREATE TABLE {old_revisions} SELECT nid, type, revisions FROM {node} WHERE revisions != ''");
-
+  }
+  else { // pgsql
+    $ret[] = update_sql("CREATE TABLE {old_revisions} AS SELECT nid, type, revisions FROM {node} WHERE revisions != ''");  
+  }
+  
+  if ($GLOBALS['db_type'] == 'mysql') {
     $ret[] = update_sql("ALTER TABLE {book} ADD KEY nid (nid)");
     $ret[] = update_sql("ALTER TABLE {forum} ADD KEY nid (nid)");
     $ret[] = update_sql("ALTER TABLE {files} ADD KEY fid (fid)");
     $ret[] = update_sql("ALTER TABLE {files} ADD KEY vid (vid)");
-    $vid = db_next_id('{node}_nid');
-    $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{node_revisions}_vid', $vid)");
   }
   else { // pgsql
-    $ret[] = update_sql("CREATE TABLE {node_revisions} AS
-                                SELECT nid, nid AS vid, uid, type, title, body, teaser, changed AS timestamp, format 
-                                FROM {node}");
-
-    $ret[] = update_sql("UPDATE {node} SET vid = nid");
-    $ret[] = update_sql("UPDATE {forum} SET vid = nid");
-    $ret[] = update_sql("UPDATE {book} SET vid = nid");
-    $ret[] = update_sql("UPDATE {files} SET vid = nid");
-
-    $ret[] = update_sql("CREATE TABLE {old_revisions} AS SELECT nid, type, revisions FROM {node} WHERE revisions != ''");
+    // TODO: IIRC KEY is the same as INDEX so only syntax is different then mysql's
   }
+  $vid = db_next_id('{node}_nid');
+  $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{node_revisions}_vid', $vid)");
 
   // Move logs too.
   $result = db_query("SELECT nid, log FROM {book} WHERE log != ''");
@@ -765,17 +779,190 @@ function update_146() {
     db_query("UPDATE {node_revisions} SET log = '%s' WHERE vid = %d", $row->log, $row->nid);
   }
 
+  db_drop_column($ret, 'book', 'log');
+  db_drop_column($ret, 'node', 'teaser');
+  db_drop_column($ret, 'node', 'body');
+  db_drop_column($ret, 'node', 'format');
+  db_drop_column($ret, 'node', 'revisions');
+
+  return $ret;
+}
+
+function pg_drop_column(&$ret, $table, $column) {
+  if ($GLOBALS['db_type'] == 'mysql' or drupal_pg_version() >= 703) {
+    $ret[] = update_sql("ALTER TABLE {". $table ."} DROP $column");
+  }
+}
+
+// FIXME: Not tested
+function db_add_primary_key(&$ret, $table, $column) {
   if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql("ALTER TABLE {book} DROP log");
-    $ret[] = update_sql("ALTER TABLE {node} DROP teaser");
-    $ret[] = update_sql("ALTER TABLE {node} DROP body");
-    $ret[] = update_sql("ALTER TABLE {node} DROP format");
-    $ret[] = update_sql("ALTER TABLE {node} DROP revisions");
+    $ret[] = update_sql("ALTER TABLE {". $table ."} ADD PRIMARY KEY $column ($column)");
   }
-  else { // pgsql
+  elseif ($GLOBALS['db_type'] == 'pgsql') {
+    $ret[] = update_sql("ALTER TABLE {". $table ."} ADD PRIMARY KEY ($column)");
   }
+}
 
-  return $ret;
+// FIXME: Not tested
+function db_drop_primary_key(&$ret, $table) {
+  if ($GLOBALS['db_type'] == 'mysql') {
+    $ret[] = update_sql("ALTER TABLE {". $table ."} DROP PRIMARY KEY");
+  }
+  elseif ($GLOBALS['db_type'] == 'pgsql') {
+    $ret[] = update_sql("ALTER TABLE {". $table ."} DROP CONSTRAINT {". $table ."}_pkey");
+  }
+}
+
+/**
+ * Adds a column to a database. Uses syntax appropriate for used db (MySQL/PostgreSQL).
+ * Saves result of SQL commands in $ret array.
+ *
+ * Note: when you add a column with NOT NULL and you are not sure if there are rows in table already,
+ *  you MUST also add DEFAULT. Otherwise PostgreSQL won't work if the table is not empty. If NOT NULL and 
+ *  DEFAULT is set the Postgresql version will set values of the added column in old rows to the DEFAULT value.
+ *
+ * Differences between MySQL and PostgreSQL:
+ * - PostgreSQL do not support _unsigned_, it's ignored.
+ * - all _tinyint_, _smallint_ etc integer-types (any type with 'int' in the name) are converted
+ *    to INTEGER for PostgreSQL.
+ * - all *text* types (longtext, mediumtext etc) are converted to TEXT for PostgreSQL
+ *
+ * TODO: add more attributes? Like primary key, key (mysql: synonim dla unique), unique, index, 
+ *       auto increment ? (mysql: must be indexed and must have a default)
+ *
+ * @param $ret 
+ *  Array to which results will be added.
+ * @param $table 
+ *  Name of the table, without {}
+ * @param $column 
+ *  Name of the column
+ * @param $type
+ *  Type of column
+ * @param $attributes
+ *  Additional optional attributes. Recognized atributes:
+ *    - unsigned    => TRUE/FALSE
+ *    - not null    => TRUE/FALSE
+ *    - default     => NULL/FALSE/value (without '')
+ * @return 
+ *  nothing, but modifies $ret parametr.
+ */
+function db_add_column(&$ret, $table, $column, $type, $attributes = array()) {
+  $pg_type = (preg_match('/int/i', $type)) ? 'int' : $type;
+  $pg_type = (preg_match('/text/i', $type)) ? 'text' : $type;
+  if (array_key_exists('unsigned', $attributes) and $attributes['unsigned']) {
+    $unsigned = 'UNSIGNED';
+  }  
+  if (array_key_exists('not null', $attributes) and $attributes['not null']) {
+    $not_null = 'NOT NULL';
+  }
+  if (array_key_exists('default', $attributes)) {
+    if (is_null($attributes['default'])) {
+      $default_val = 'NULL'; 
+      $default = 'DEFAULT NULL';
+    }
+    elseif ($attributes['defaul'] === FALSE) {
+      $default = '';
+    } 
+    else {
+      $default_val = "'$attributes[default]'"; 
+      $default = "DEFAULT '$attributes[default]'";
+    }
+  }
+  
+  if ($GLOBALS['db_type'] == 'mysql') {
+    $ret[] = update_sql("ALTER TABLE {". $table ."} ADD $column $type $not_null $default $unsigned");
+  }
+  elseif ($GLOBALS['db_type'] == 'pgsql') {
+    $ret[] = update_sql("ALTER TABLE {". $table ."} ADD $column $pg_type");
+    if ($default) {
+      $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column SET $default");
+    }
+    if ($not_null) {
+      if ($default) {
+        $ret[] = update_sql("UPDATE {". $table ."} SET $column = $default_val");
+      }
+      $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column SET NOT NULL");
+    }
+  }
+}
+
+/**
+ * Changes a column definition. Uses syntax appropriate for used db (MySQL/PostgreSQL).
+ * Saves result of SQL commands in $ret array.
+ *
+ * Differences between MySQL and PostgreSQL:
+ * - PostgreSQL do not support _unsigned_, it's ignored.
+ * - all _tinyint_, _smallint_ etc integer-types (any type with 'int' in the name) are converted
+ *    to INTEGER for PostgreSQL.
+ * - all *text* types (longtext, mediumtext etc) are converted to TEXT for PostgreSQL
+ * - FIXME: when changing a column in mysql the PRIMARY KEY attribute is retained. In Postgres, due to the 
+ *    nature of changing process (i.e. dropping a column) this attribute is dropped. How to workaround it?
+ *    Need to check other attributes too (e.g. NOT NULL, index etc).
+ *
+ * TODO: add more attributes? Like primary key, key (mysql: synonim dla unique), unique, index, 
+ *       auto increment ? (mysql: must be indexed and must have a default)
+ *
+ * TODO: when setting NOT NOLL, and DEFAULT is set, update the table to default WHERE column IS NULL ?
+ *
+ * @param $ret 
+ *  Array to which results will be added.
+ * @param $table 
+ *  Name of the table, without {}
+ * @param $column 
+ *  Name of the column to change
+ * @param $column_new
+ *  New name for the column (set to the same as $column if you don't want to change the name)
+ * @param $type
+ *  Type of column
+ * @param $attributes
+ *  Additional optional attributes. Recognized atributes:
+ *    - unsigned    => TRUE/FALSE
+ *    - not null    => TRUE/FALSE
+ *    - default     => NULL/FALSE/value (without '')
+ * @return 
+ *  nothing, but modifies $ret parametr.
+ */
+function db_change_column(&$ret, $table, $column, $column_new, $type, $attributes = array()) {
+  $pg_type = (preg_match('/int/i', $type)) ? 'int' : $type;
+  $pg_type = (preg_match('/text/i', $type)) ? 'text' : $type;
+  if (array_key_exists('unsigned', $attributes) and $attributes['unsigned']) {
+    $unsigned = 'UNSIGNED';
+  }  
+  if (array_key_exists('not null', $attributes) and $attributes['not null']) {
+    $not_null = 'NOT NULL';
+  }
+  if (array_key_exists('default', $attributes)) {
+    if (is_null($attributes['default'])) {
+      $default_val = 'NULL'; 
+      $default = 'DEFAULT NULL';
+    }
+    elseif ($attributes['default'] === FALSE) {
+      $default = '';
+    } 
+    else {
+      $default_val = "'$attributes[default]'"; 
+      $default = "DEFAULT '$attributes[default]'";
+    }
+  }
+  
+  if ($GLOBALS['db_type'] == 'mysql') {
+    $ret[] = update_sql("ALTER TABLE {". $table ."} CHANGE $column $column_new $type $not_null $default $unsigned");
+  }
+  elseif ($GLOBALS['db_type'] == 'pgsql') {
+    $ret[] = update_sql("ALTER TABLE {". $table ."} RENAME $column TO ". $column ."_old");
+    $ret[] = update_sql("ALTER TABLE {". $table ."} ADD $column_new $pg_type");
+    $ret[] = update_sql("UPDATE {". $table ."} SET $column_new = ". $column ."_old");
+    if ($default) {
+      $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column_new SET $default");
+    }
+    if ($not_null) {
+      $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column_new SET NOT NULL");
+    }
+    if (drupal_pg_version() >= 703) {
+      $ret[] = update_sql("ALTER TABLE {". $table ."} DROP ". $column ."_old");
+    }
+  }
 }
 
 function update_sql($sql) {
Tylko w drupal-head-revisions/database: updates.inc.orig
diff -rup drupal-head-revisions_43/includes/database.pgsql.inc drupal-head-revisions/includes/database.pgsql.inc
--- drupal-head-revisions_43/includes/database.pgsql.inc	2005-08-28 23:28:01.000000000 +0200
+++ drupal-head-revisions/includes/database.pgsql.inc	2005-08-28 23:28:58.000000000 +0200
@@ -256,6 +256,28 @@ function db_escape_string($text) {
 }
 
 /**
+ * Returns PostgreSQL database version.
+ * Currently only main and sub version are considered, but this can be extended if needed.
+ * @return
+ *  Number in the form of xyy, where x is main version, yy is sub version. For example 7.4 is returned
+ *  as 704, 8.0.3 as 800. When 7.12 comes out it will be returned as 712.
+ * @return
+ *  0 if it can not recognize the version.
+ */
+function drupal_pg_version() {
+  static $version = NULL;
+  
+  if ($version !== NULL) { return $version; }
+
+  $result = db_result(db_query('SELECT version()'));
+  if (! $result or ! preg_match("/(\d+)\.(\d+)/", $result, $matches) ) {
+    return $version = 0;
+  }
+  
+  return $version = sprintf('%d%02d', $matches[1], $matches[2]);
+}
+
+/**
  * @} End of "ingroup database".
  */
 
