Index: uuid.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uuid/uuid.admin.inc,v
retrieving revision 1.1.2.8
diff -u -p -r1.1.2.8 uuid.admin.inc
--- uuid.admin.inc	8 Sep 2010 16:07:14 -0000	1.1.2.8
+++ uuid.admin.inc	30 Sep 2010 18:58:01 -0000
@@ -128,9 +128,9 @@ function uuid_sync() {
     }
 
     // Revisions.
-    $result = db_query("SELECT nr.vid AS vid FROM {node_revisions} AS nr INNER JOIN {node} n ON nr.nid = n.nid WHERE n.type IN (" . $placeholders . ") AND nr.vid NOT IN (SELECT vid FROM {uuid_node_revisions})", $types);
+    $result = db_query("SELECT nr.vid AS vid, nr.nid AS nid FROM {node_revisions} AS nr INNER JOIN {node} n ON nr.nid = n.nid WHERE n.type IN (" . $placeholders . ") AND nr.vid NOT IN (SELECT vid FROM {uuid_node_revisions})", $types);
     while ($item = db_fetch_object($result)) {
-      db_query("INSERT INTO {uuid_node_revisions} (vid, uuid) VALUES(%d, '%s')", $item->vid, uuid_uuid());
+      db_query("INSERT INTO {uuid_node_revisions} (vid, uuid, nid) VALUES(%d, '%s', %d)", $item->vid, uuid_uuid(), $item->nid);
     }
   }
 
Index: uuid.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uuid/uuid.install,v
retrieving revision 1.1.2.9
diff -u -p -r1.1.2.9 uuid.install
--- uuid.install	8 Sep 2010 16:07:14 -0000	1.1.2.9
+++ uuid.install	30 Sep 2010 18:58:01 -0000
@@ -26,7 +26,7 @@ function uuid_install() {
  * Implementation of hook_schema().
  */
 function uuid_schema() {
-  return array(
+  $schema = array(
     'uuid_node' => uuid_table_schema('node', 'nid'),
     'uuid_node_revisions' => uuid_table_schema('node_revisions', 'vid'),
     'uuid_users' => uuid_table_schema('users', 'uid'),
@@ -34,6 +34,19 @@ function uuid_schema() {
     'uuid_term_data' => uuid_table_schema('term_data', 'tid'),
     'uuid_comments' => uuid_table_schema('comments', 'cid'),
   );
+  // The uuid_node_revisions table requires an additional column (node id) to
+  // support revision deletion upon node delete. No index is needed on this
+  // column as it will only be used during a node delete.
+  $schema['uuid_node_revisions']['fields']['nid'] = array(
+    'type' => 'int',
+    'length' => 10,
+    'unsigned' => TRUE,
+    'not null' => TRUE,
+    'default' => 0,
+    'description' => 'The revision\'s node id. Needed for delete node operations.',
+  );
+
+  return $schema;
 }
 
 /**
@@ -120,3 +133,33 @@ function uuid_update_6003() {
 
   return $ret;
 }
+
+/**
+ * Modify existing uuid_node_revisions table to support revision deletion, and
+ * add in as much legacy data as possible.
+ */
+function uuid_update_6004() {
+  $ret = array();
+
+  if (db_table_exists('uuid_node_revisions')) {
+    // Use what's already defined in uuid schema in order to be consistent.
+    $schema = uuid_schema();
+    $spec = $schema['uuid_node_revisions']['fields']['nid'];
+    db_add_field($ret, 'uuid_node_revisions', 'nid', $spec);
+    // Add node ids to the new column, for revisions that exist, but now have a
+    // default value of 0 in uuid_node_revisions.
+    $result = db_query('SELECT nr.nid, nr.vid FROM {node_revisions} AS nr LEFT JOIN {uuid_node_revisions} AS unr ON unr.vid=nr.vid WHERE unr.nid=%d', 0);
+    while ($item = db_fetch_object($result)) {
+      $ret[] = update_sql('UPDATE {uuid_node_revisions} SET nid='. (int) $item->nid .' WHERE vid='. (int) $item->vid);
+    }
+    // Add uuid_node_revision rows for rows that don't exist, but should.
+    $result = db_query('SELECT nr.nid, nr.vid FROM {node_revisions} AS nr LEFT JOIN {uuid_node_revisions} AS unr ON unr.vid=nr.vid WHERE unr.nid IS NULL');
+    while ($item = db_fetch_object($result)) {
+      $ret[] = update_sql(sprintf("INSERT INTO {uuid_node_revisions} (vid, uuid, nid) VALUES(%d, '%s', %d)", $item->vid, uuid_uuid(), $item->nid));
+    }
+    // Delete any orphaned revision vid, uuid pairs.
+    $ret[] = update_sql('DELETE FROM {uuid_node_revisions} WHERE nid=0');
+  }
+
+  return $ret;
+}
Index: uuid.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uuid/uuid.module,v
retrieving revision 1.1.2.15
diff -u -p -r1.1.2.15 uuid.module
--- uuid.module	24 Sep 2010 05:08:07 -0000	1.1.2.15
+++ uuid.module	30 Sep 2010 18:58:01 -0000
@@ -47,32 +47,36 @@ function uuid_nodeapi(&$node, $op, $teas
         db_query("INSERT INTO {uuid_node} (nid, uuid) VALUES (%d, '%s')", $node->nid, $node->uuid);
 
         if (isset($node->revision_uuid) && uuid_is_valid($node->revision_uuid)) {
-          db_query("INSERT INTO {uuid_node_revisions} (vid, uuid) VALUES (%d, '%s')", $node->vid, $node->revision_uuid);
+          db_query("INSERT INTO {uuid_node_revisions} (vid, uuid, nid) VALUES (%d, '%s', %d)", $node->vid, $node->revision_uuid, $node->nid);
         }
         else {
-          db_query("INSERT INTO {uuid_node_revisions} (vid, uuid) VALUES (%d, '%s')", $node->vid, uuid_uuid());
+          // Attach new revision uuid to node, don't just insert it.
+          $node->revision_uuid = uuid_uuid();
+          db_query("INSERT INTO {uuid_node_revisions} (vid, uuid, nid) VALUES (%d, '%s', %d)", $node->vid, $node->revision_uuid, $node->nid);
         }
       }
-      else if (in_array($node->type, $automatic_types)) {
+      elseif (in_array($node->type, $automatic_types)) {
         $node->uuid = uuid_uuid();
         $node->revision_uuid = uuid_uuid();
         db_query("INSERT INTO {uuid_node} (nid, uuid) VALUES (%d, '%s')", $node->nid, $node->uuid);
-        db_query("INSERT INTO {uuid_node_revisions} (vid, uuid) VALUES (%d, '%s')", $node->vid, $node->revision_uuid);
+        db_query("INSERT INTO {uuid_node_revisions} (vid, uuid, nid) VALUES (%d, '%s', %d)", $node->vid, $node->revision_uuid, $node->nid);
       }
       break;
     case 'update':
       if (isset($node->revision)) {
         if (isset($node->revision_uuid) && uuid_is_valid($node->revision_uuid) && $node->revision_uuid != $node->loaded_revision_uuid) {
-          db_query("INSERT INTO {uuid_node_revisions} (vid, uuid) VALUES (%d, '%s')", $node->vid, $node->revision_uuid);
+          db_query("INSERT INTO {uuid_node_revisions} (vid, uuid, nid) VALUES (%d, '%s', %d)", $node->vid, $node->revision_uuid, $node->nid);
         }
         else {
           $node->revision_uuid = uuid_uuid();
-          db_query("INSERT INTO {uuid_node_revisions} (vid, uuid) VALUES (%d, '%s')", $node->vid, $node->revision_uuid);
+          db_query("INSERT INTO {uuid_node_revisions} (vid, uuid, nid) VALUES (%d, '%s', %d)", $node->vid, $node->revision_uuid, $node->nid);
         }
       }
       break;
     case 'delete':
       db_query('DELETE FROM {uuid_node} WHERE nid = %d', $node->nid);
+      // Delete the revision uuids for the node.
+      db_query('DELETE FROM {uuid_node_revisions} WHERE nid = %d', $node->nid);
       break;
     case 'delete revision':
       db_query('DELETE FROM {uuid_node_revisions} WHERE vid = %d', $node->vid);
@@ -107,6 +111,8 @@ function node_get_by_uuid($uuid) {
 /**
  * Returns the node associated with a revision UUID.
  *
+ * @param string $revision_uuid The uuid to use for the node lookup.
+ *
  * @return
  *   Either the $node object, or FALSE on failure.
  */
@@ -190,7 +196,7 @@ function uuid_taxonomy($op, $type, $arra
       'field' => 'vid',
     ),
   );
-  
+
   if (array_key_exists($type, $types) && in_array($array['vid'], variable_get('uuid_automatic_for_taxonomy', array()))) {
     $field = $types[$type]['field'];
     switch ($op) {
@@ -223,7 +229,7 @@ function uuid_comment(&$a1, $op) {
         db_query("INSERT INTO {uuid_comments} (cid, uuid) VALUES (%d, '%s')", $a1['cid'], uuid_uuid());
       }
       break;
-      
+
     case 'update':
       if (isset($a1['uuid']) && uuid_is_valid($a1['uuid'])) {
         $exists = db_result(db_query('SELECT 1 FROM {uuid_comments} WHERE cid = %d', $a1['cid']));
