Index: /trunk/tools/collapse_diffinputs.pl
===================================================================
--- /trunk/tools/collapse_diffinputs.pl	(revision 21006)
+++ /trunk/tools/collapse_diffinputs.pl	(revision 21007)
@@ -34,10 +34,12 @@
     stack1,
     warp2,
-    stack2
+    stack2,
+    skycell_id
     FROM
         (select
             diff_id,
             warp1 as warp1,
-            stack2 as stack1
+            stack2 as stack1,
+            skycell_id as skycell_id
         from diffInputSkyfile
         WHERE template = 0
@@ -47,5 +49,6 @@
             diff_id,
             warp1 as warp2,
-            stack2 as stack2
+            stack2 as stack2,
+            skycell_id as stack_skycell
         from diffInputSkyfile
         WHERE template = 1
@@ -68,4 +71,5 @@
     my $stack1 = $ref->{stack1};
     my $stack2 = $ref->{stack2};
+    my $skycell_id = $ref->{skycell_id};
 
     # reorganizing columns puts warp1 and stack 1 correctly for template.
@@ -87,4 +91,7 @@
         die "unexpected input set for $diff_id";
     }
+
+    # set skycell_id in any existing diffSkyfile
+    $dbh->do("UPDATE diffSkyfile set skycell_id = ? where diff_id = ?", undef, $skycell_id, $diff_id);
 
     #
