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	23 Sep 2010 00:32:09 -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	23 Sep 2010 00:32:09 -0000
@@ -28,7 +28,7 @@ function uuid_install() {
 function uuid_schema() {
   return array(
     'uuid_node' => uuid_table_schema('node', 'nid'),
-    'uuid_node_revisions' => uuid_table_schema('node_revisions', 'vid'),
+    'uuid_node_revisions' => uuid_node_revisions_table_schema('vid'),
     'uuid_users' => uuid_table_schema('users', 'uid'),
     'uuid_vocabulary' => uuid_table_schema('vocabulary', 'vid'),
     'uuid_term_data' => uuid_table_schema('term_data', 'tid'),
@@ -71,6 +71,35 @@ function uuid_table_schema($table, $key 
 }
 
 /**
+ * Return schema for the uuid node revision table.
+ *
+ * @param $key
+ *   Name of key field, e.g. nid for nodes.
+ *
+ * @return
+ *   Array with table structure definition (schema).
+ */
+function uuid_node_revisions_table_schema($key = 'key') {
+  // get the standard schema
+  $schema = uuid_table_schema('uuid_node_revisions', $key);
+
+  // add the node id column
+  if (is_array($schema) && isset($schema['fields'])) {
+    // no index needed on this column as it will only
+    // be used during a node delete.
+    $schema['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;
+}
+
+/**
  * Implementation of hook_uninstall().
  */
 function uuid_uninstall() {
@@ -118,5 +147,25 @@ function uuid_update_6003() {
 
   db_create_table($ret, 'uuid_comments', uuid_table_schema('comments', 'cid'));
 
+  if (db_table_exists('uuid_node_revisions')) {
+    // use what's in uuid_table_schema in order to be consistent
+    $field_specs = uuid_node_revisions_table_schema('vid');
+    $spec = $field_specs['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 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.14
diff -u -p -r1.1.2.14 uuid.module
--- uuid.module	21 Sep 2010 14:40:40 -0000	1.1.2.14
+++ uuid.module	23 Sep 2010 00:32:09 -0000
@@ -47,29 +47,37 @@ 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
+          $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)) {
         db_query("INSERT INTO {uuid_node} (nid, uuid) VALUES (%d, '%s')", $node->nid, uuid_uuid());
-        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
+        $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);
       }
       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 {
-          db_query("INSERT INTO {uuid_node_revisions} (vid, uuid) VALUES (%d, '%s')", $node->vid, uuid_uuid());
+          // Attach to node for later use
+          $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);
         }
       }
       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);
@@ -104,17 +112,34 @@ function node_get_by_uuid($uuid) {
 /**
  * Returns the node associated with a revision UUID.
  *
+ * @todo One thing to ascertain here is whether this function
+ * should only return the node if the revision's uuid is the
+ * active revision for that node, or if it should also return
+ * the node even if the revision is not the active one. We
+ * make active-only the default implementation for now, just
+ * to be on the safe side.
+ *
+ * @param string $revision_uuid The uuid to use for the node
+ * lookup
+ * @param bool $active_only Should a node only be returned if
+ * the passed revision uuid is the currently active one for
+ * the node? Default: TRUE
  * @return
  *   Either the $node object, or FALSE on failure.
  */
-function node_get_by_revision_uuid($revision_uuid) {
-  $node = db_fetch_object(db_query(db_rewrite_sql(
-    "SELECT n.nid, n.vid
-     FROM {node} AS n
-     INNER JOIN {uuid_node_revisions} AS unr ON n.vid = unr.vid
-     WHERE unr.uuid = '%s'"),
-    $revision_uuid
-  ));
+function node_get_by_revision_uuid($revision_uuid, $active_only=TRUE) {
+  if ($active_only) {
+    $node = db_fetch_object(db_query(db_rewrite_sql(
+      "SELECT n.nid, n.vid
+       FROM {node} AS n
+       INNER JOIN {uuid_node_revisions} AS unr ON n.vid = unr.vid
+       WHERE unr.uuid = '%s'"),
+      $revision_uuid
+    ));
+  }
+  else {
+    $node = db_fetch_object(db_query("SELECT nid, vid FROM {uuid_node_revisions} WHERE uuid = '%s'", $revision_uuid));
+  }
 
   if ($node->nid && $node->vid) {
     return node_load($node->nid, $node->vid);
