? cvs_get_vanilla.sh
Index: database/updates.inc
===================================================================
RCS file: /cvs/drupal/drupal/database/updates.inc,v
retrieving revision 1.155
diff -u -p -r1.155 updates.inc
--- database/updates.inc	7 Dec 2005 21:13:58 -0000	1.155
+++ database/updates.inc	8 Dec 2005 00:23:13 -0000
@@ -467,12 +467,98 @@ function system_update_129() {
   return $ret;
 }
 
-function system_update_130() {
-  $ret = array();
 
-  // This update has been moved to update_fix_sessions in update.php because it
-  // is needed for the basic functioning of the update script.
+function _pg_prefix_ok($table) {
+  global $db_prefix;
+  
+  $prefix = $db_prefix;
+  if (is_array($db_prefix)) {
+    $prefix = array_key_exists($table, $db_prefix) ? $db_prefix[$table] : $db_prefix['default'];
+  }
+  
+  if ($db_prefix === '' || strstr($db_prefix, '.') == '.') { 
+    return TRUE; // No prefix or schema prefix - all ok.
+  }
+  return FALSE; // foo_ type prefix  
+}
+
+function _pg_redo_pk(&$ret, $table, $columns) {
+  if (_pg_prefix_ok($table)) { return; }
+  $ret[] = update_sql('ALTER TABLE {'. $table .'} DROP CONSTRAINT {'. $table .'}_pkey');
+  $ret[] = update_sql('ALTER TABLE {'. $table .'} ADD CONSTRAINT '. $table ."_pkey PRIMARY KEY($columns)");
+}
+
+function _pg_redo_unique(&$ret, $table, $columns) {
+  if (_pg_prefix_ok($table)) { return; }
+  $underscored = strtr($columns, ',', '_');
+  $ret[] = update_sql('ALTER TABLE {'. $table .'} DROP CONSTRAINT {'. $table ."}_{$underscored}_key");
+  $ret[] = update_sql('ALTER TABLE {'. $table ."} ADD CONSTRAINT {$table}_{$underscored}_key UNIQUE($columns)"); // Some {}s are eaten by PHP (RTFM)
+}
 
+function system_update_130() {
+  $ret = array();
+  
+  switch ($GLOBALS['db_type']) {
+    case 'pgsql':
+  
+      _pg_redo_pk($ret, 'access', 'aid');
+      _pg_redo_pk($ret, 'accesslog', 'aid');
+      _pg_redo_pk($ret, 'aggregator_category', 'cid');
+      _pg_redo_unique($ret, 'aggregator_category', 'title');
+      _pg_redo_pk($ret, 'aggregator_category_feed', 'fid,cid');
+      _pg_redo_pk($ret, 'aggregator_category_item', 'iid,cid');  
+      _pg_redo_pk($ret, 'aggregator_feed', 'fid');
+      _pg_redo_unique($ret, 'aggregator_feed', 'url');
+      _pg_redo_unique($ret, 'aggregator_feed', 'title');
+      _pg_redo_pk($ret, 'aggregator_item', 'iid');
+      _pg_redo_pk($ret, 'authmap', 'aid');
+      _pg_redo_unique($ret, 'authmap', 'authname');
+      _pg_redo_pk($ret, 'book', 'nid');
+      _pg_redo_pk($ret, 'boxes', 'bid');
+      _pg_redo_unique($ret, 'boxes', 'info');
+      _pg_redo_unique($ret, 'boxes', 'title');
+      _pg_redo_pk($ret, 'cache', 'cid');
+      _pg_redo_pk($ret, 'comments', 'cid');
+      _pg_redo_pk($ret, 'node_comment_statistics', 'nid');
+      _pg_redo_pk($ret, 'directory', 'link');
+      _pg_redo_pk($ret, 'files', 'fid');
+      _pg_redo_pk($ret, 'filter_formats', 'format');
+      _pg_redo_pk($ret, 'forum', 'nid');
+      _pg_redo_pk($ret, 'history', 'uid,nid');
+      _pg_redo_pk($ret, 'locales_meta', 'locale');
+      _pg_redo_pk($ret, 'locales_source', 'lid');
+      _pg_redo_unique($ret, 'locales_target', 'lid');
+      _pg_redo_pk($ret, 'menu', 'mid');
+      _pg_redo_pk($ret, 'moderation_filters', 'fid');
+      _pg_redo_pk($ret, 'moderation_votes', 'mid');
+      _pg_redo_pk($ret, 'node', 'nid');
+      _pg_redo_pk($ret, 'node_access', 'nid,gid,realm');
+      _pg_redo_pk($ret, 'node_counter', 'nid');
+      _pg_redo_pk($ret, 'profile_fields', 'fid');
+      _pg_redo_unique($ret, 'profile_fields', 'name');
+      _pg_redo_pk($ret, 'url_alias', 'pid');
+      _pg_redo_pk($ret, 'poll', 'nid');
+      _pg_redo_pk($ret, 'poll_choices', 'chid');
+      _pg_redo_pk($ret, 'queue', 'nid,uid');
+      _pg_redo_pk($ret, 'role', 'rid');
+      _pg_redo_unique($ret, 'role', 'name');
+      _pg_redo_pk($ret, 'sessions', 'sid');
+      _pg_redo_pk($ret, 'system', 'filename');
+      _pg_redo_pk($ret, 'term_data', 'tid');
+      _pg_redo_pk($ret, 'term_node', 'tid,nid');
+      _pg_redo_pk($ret, 'users', 'uid');
+      _pg_redo_unique($ret, 'users', 'name');
+      _pg_redo_pk($ret, 'users_roles', 'uid,rid');
+      _pg_redo_pk($ret, 'variable', 'name');
+      _pg_redo_pk($ret, 'vocabulary', 'vid');
+      _pg_redo_pk($ret, 'vocabulary_node_types', 'vid,type');
+      _pg_redo_pk($ret, 'watchdog', 'wid');
+
+    break;
+  case 'mysql':
+  case 'mysqli':
+    break;
+  }
   return $ret;
 }
 
@@ -484,7 +570,7 @@ function system_update_131() {
     // Removed recreation of the index, which is not present in the db schema
   }
   elseif ($GLOBALS['db_type'] == 'pgsql') {
-    $ret[] = update_sql("ALTER TABLE {boxes} DROP CONSTRAINT {boxes}_title_key");
+    $ret[] = update_sql("ALTER TABLE {boxes} DROP CONSTRAINT boxes_title_key");
   }
 
   return $ret;
@@ -662,7 +748,7 @@ function system_update_143() {
       category varchar(255) NOT NULL default '',
       recipients text NOT NULL default '',
       reply text NOT NULL default '',
-      PRIMARY KEY (category))");
+      CONSTRAINT contact_pkey PRIMARY KEY (category))");
   }
 
   return $ret;
@@ -768,7 +854,7 @@ function system_update_146() {
       log text NOT NULL default '',
       timestamp integer NOT NULL default '0',
       format int NOT NULL default '0',
-      PRIMARY KEY  (nid,vid))");
+      CONSTRAINT node_revisions_pkey PRIMARY KEY (nid,vid))");
     $ret[] = update_sql("INSERT INTO {node_revisions}
       SELECT nid, nid AS vid, uid, title, body, teaser, changed AS timestamp, format
       FROM {node}");
@@ -781,17 +867,17 @@ function system_update_146() {
     db_add_column($ret, 'book',  'vid', 'int', array('not null' => TRUE, 'default' => 0));
     db_add_column($ret, 'forum', 'vid', 'int', array('not null' => TRUE, 'default' => 0));
 
-    $ret[] = update_sql("ALTER TABLE {book} DROP CONSTRAINT {book}_pkey");
-    $ret[] = update_sql("ALTER TABLE {forum} DROP CONSTRAINT {forum}_pkey");
-    $ret[] = update_sql("ALTER TABLE {files} DROP CONSTRAINT {files}_pkey");
+    $ret[] = update_sql("ALTER TABLE {book} DROP CONSTRAINT book_pkey");
+    $ret[] = update_sql("ALTER TABLE {forum} DROP CONSTRAINT forum_pkey");
+    $ret[] = update_sql("ALTER TABLE {files} DROP CONSTRAINT files_pkey");
 
     $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)");
-    $ret[] = update_sql("ALTER TABLE {forum} ADD PRIMARY KEY (nid)"); // We, The Postgres, will do it database.* way, not update() way.
+    $ret[] = update_sql("ALTER TABLE {book} ADD CONSTRAINT book_pkey PRIMARY KEY (vid)");
+    $ret[] = update_sql("ALTER TABLE {forum} ADD CONSTRAINT forum_pkey PRIMARY KEY (nid)"); // We, The Postgres, will do it database.* way, not update() way.
 
     $ret[] = update_sql("CREATE TABLE {old_revisions} AS SELECT nid, type, revisions FROM {node} WHERE revisions != ''");
 
@@ -932,7 +1018,7 @@ function system_update_150() {
       $ret[] = update_sql("CREATE TABLE {search_total} (
         word varchar(50) NOT NULL default '',
         count float default NULL,
-        PRIMARY KEY(word))");
+        CONSTRAINT search_total_pkey PRIMARY KEY(word))");
       break;
     default:
       break;
@@ -1037,11 +1123,11 @@ function system_update_153(){
   $ret = array();
   switch ($GLOBALS['db_type']) {
     case 'pgsql':
-      $ret[] = update_sql("ALTER TABLE {contact} DROP CONSTRAINT {contact}_pkey");
+      $ret[] = update_sql("ALTER TABLE {contact} DROP CONSTRAINT contact_pkey");
       $ret[] = update_sql("CREATE SEQUENCE {contact}_cid_seq");
       db_add_column($ret, 'contact', 'cid', 'int', array('not null' => TRUE, 'default' => "nextval('{contact}_cid_seq')"));
-      $ret[] = update_sql("ALTER TABLE {contact} ADD PRIMARY KEY (cid)");
-      $ret[] = update_sql("ALTER TABLE {contact} ADD CONSTRAINT {contact}_category_key UNIQUE (category)");
+      $ret[] = update_sql("ALTER TABLE {contact} ADD CONSTRAINT contact_pkey PRIMARY KEY (cid)");
+      $ret[] = update_sql("ALTER TABLE {contact} ADD CONSTRAINT contact_category_key UNIQUE (category)");
       break;
     case 'mysql':
     case 'mysqli':
@@ -1082,7 +1168,7 @@ function system_update_155() {
         expire integer NOT NULL default '0',
         created integer NOT NULL default '0',
         headers text default '',
-        PRIMARY KEY (cid)
+        CONSTRAINT cache_pkey PRIMARY KEY (cid)
         )");
       $ret[] = update_sql("CREATE INDEX {cache}_expire_idx ON {cache}(expire)");
       break;
