Index: trunk/ippTools/src/difftool.c
===================================================================
--- trunk/ippTools/src/difftool.c	(revision 14243)
+++ trunk/ippTools/src/difftool.c	(revision 14250)
@@ -236,31 +236,13 @@
     }
 
+    psString stack_id = psMetadataLookupStr(&status, config->args, "-stack_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -stack_id");
+        return false;
+    }
+
     psString warp_id = psMetadataLookupStr(&status, config->args, "-warp_id");
     if (!status) {
         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -warp_id");
-        return false;
-    }
-    if (!diff_id) {
-        psError(PS_ERR_UNKNOWN, true, "-diff_id is required");
-        return false;
-    }
-
-    psString skycell_id = psMetadataLookupStr(&status, config->args, "-skycell_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -skycell_id");
-        return false;
-    }
-    if (!skycell_id) {
-        psError(PS_ERR_UNKNOWN, true, "-skycell_id is required");
-        return false;
-    }
-
-    psString tess_id = psMetadataLookupStr(&status, config->args, "-tess_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -tess_id");
-        return false;
-    }
-    if (!tess_id) {
-        psError(PS_ERR_UNKNOWN, true, "-tess_id is required");
         return false;
     }
@@ -279,14 +261,48 @@
     }
 
-    // XXX need to validate the warp_id here
-    // XXX instead of validiting it here we should just use forgein key
-    // constrants
+    // must provide either stack_id or warp_id but not BOTH
+    if (!(stack_id || warp_id)) {
+        psError(PS_ERR_UNKNOWN, true, "either -stack_id or -warp_id must be specified");
+        return false;
+    }
+    if (stack_id && warp_id) {
+        psError(PS_ERR_UNKNOWN, true, "either -stack_id or -warp_id must be specified"); 
+        return false;
+    }
+
+    // if a warp_id was provided we need to lookup the skycell_id and tess_id
+    // from the warpRun
+    psString skycell_id = NULL;
+    psString tess_id = NULL;
+    if (warp_id) {
+        if (!p_psDBRunQuery(config->dbh, "SELECT * from diffRun WHERE diff_id = %" PRId64, (psS64)atoll(diff_id))) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+            return false;
+        }
+
+        psArray *output = p_psDBFetchResult(config->dbh);
+        if (!output) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+            return false;
+        }
+        if (!psArrayLength(output)) {
+            psError(PS_ERR_UNKNOWN, false, "diff_id %" PRId64 " not found", (psS64)atoll(diff_id));
+            psFree(output);
+            return false;
+        }
+
+        diffRunRow *run = diffRunObjectFromMetadata(output->data[0]);
+        skycell_id = run->skycell_id;
+        tess_id = run->tess_id;
+    }
+
     if (!diffInputSkyfileInsert(config->dbh,
             (psS64)atoll(diff_id),
-            (psS64)atoll(warp_id),
+            template,
+            stack_id ? (psS64)atoll(stack_id) : PS_MAX_S64, // defined or NULL
+            warp_id ? (psS64)atoll(warp_id) : PS_MAX_S64, // defined or NULL
             skycell_id,
             tess_id,
-            kind,
-            template
+            kind
         )) {
         psError(PS_ERR_UNKNOWN, false, "database error");
Index: trunk/ippTools/src/difftoolConfig.c
===================================================================
--- trunk/ippTools/src/difftoolConfig.c	(revision 14243)
+++ trunk/ippTools/src/difftoolConfig.c	(revision 14250)
@@ -78,9 +78,7 @@
             "define diff ID (required)", NULL);
     psMetadataAddStr(addinputskyfileArgs, PS_LIST_TAIL, "-warp_id", 0,
-            "define warp ID (required)", NULL);
-    psMetadataAddStr(addinputskyfileArgs, PS_LIST_TAIL, "-skycell_id", 0,
-            "define by skycell ID (required)", NULL);
-    psMetadataAddStr(addinputskyfileArgs, PS_LIST_TAIL, "-tess_id", 0,
-            "dfine tess ID (required)", NULL);
+            "define warp ID", NULL);
+    psMetadataAddStr(addinputskyfileArgs, PS_LIST_TAIL, "-stack_id", 0,
+            "define stack ID)", NULL);
     psMetadataAddStr(addinputskyfileArgs, PS_LIST_TAIL, "-kind", 0,
             "define kind", NULL);
Index: trunk/ippTools/src/pxtables.c
===================================================================
--- trunk/ippTools/src/pxtables.c	(revision 14243)
+++ trunk/ippTools/src/pxtables.c	(revision 14250)
@@ -83,10 +83,10 @@
     CREATE_TABLE(warpSkyCellMapCreateTable);
     CREATE_TABLE(warpSkyfileCreateTable);
+    CREATE_TABLE(stackRunCreateTable);
+    CREATE_TABLE(stackInputSkyfileCreateTable);
+    CREATE_TABLE(stackSumSkyfileCreateTable);
     CREATE_TABLE(diffRunCreateTable);
     CREATE_TABLE(diffInputSkyfileCreateTable);
     CREATE_TABLE(diffSkyfileCreateTable);
-    CREATE_TABLE(stackRunCreateTable);
-    CREATE_TABLE(stackInputSkyfileCreateTable);
-    CREATE_TABLE(stackSumSkyfileCreateTable);
 
     return true;
