Index: content.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/Attic/content.install,v
retrieving revision 1.85.2.33
diff -u -p -r1.85.2.33 content.install
--- content.install	14 Jul 2009 22:17:05 -0000	1.85.2.33
+++ content.install	3 Feb 2011 03:02:09 -0000
@@ -618,4 +618,55 @@ function content_update_6010(&$sandbox) 
     $ret['#finished'] = 1 - count($sandbox['tables']) / $sandbox['count'];
   }
   return $ret;
-}
\ No newline at end of file
+}
+
+/**
+ * Fix schema mis-matches in sites upgraded from Drupal 5
+ * See http://drupal.org/node/642190
+ */
+function content_update_6011(&$sandbox) {
+  if ($abort = content_check_update()) {
+    return $abort;
+  }
+  $ret = array();
+
+  // These fields should be tinyints, and db_storage should default to 1.
+  db_change_field($ret, 'content_node_field', 'required', 'required', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0));
+  db_change_field($ret, 'content_node_field', 'multiple', 'multiple', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0));
+  db_change_field($ret, 'content_node_field', 'db_storage', 'db_storage', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 1));
+
+  // nid columns in nodereference field tables from Drupal 5 are signed,
+  // and should be unsigned. The following code is adapted from the
+  // dynamic schema generation in content_schema().
+  $schema = array();
+  $db_result = db_query("SELECT * FROM {". content_instance_tablename() ."} nfi ".
+    " LEFT JOIN {". content_field_tablename() ."} nf ON nf.field_name = nfi.field_name WHERE nf.active = 1 AND nfi.widget_active = 1 AND nf.type = 'nodereference'");
+  while ($field = db_fetch_array($db_result)) {
+    $field['columns'] = unserialize($field['db_columns']);
+    unset($field['db_columns']);
+    $field_table = _content_tablename($field['field_name'], CONTENT_DB_STORAGE_PER_FIELD);
+    $base_schema = content_table_schema($field);
+    if ($field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) {
+      if (!isset($schema[$field_table])) {
+        $schema[$field_table] = $base_schema;
+      }
+    }
+  }
+
+  // We now have the nodereference field table schemas, and
+  // can change the necessary fields.
+  $nodereference_tables = $schema;
+  foreach ($nodereference_tables as $table => $field_schema) {
+    $field = $field_schema['content fields'][0] . '_nid';
+    $spec = $field_schema['fields'][$field];
+    foreach (array_keys($field_schema['indexes']) as $name) {
+      db_drop_index($ret, $table, $name);
+    }
+    db_drop_primary_key($ret, $table);
+    db_change_field($ret, $table, $field, $field, $spec, $field_schema);
+  }
+
+  // Is this needed? It was not done for update 6010.
+  #variable_set('content_schema_version', 6011);
+  return $ret;
+}
