Index: branches/eam_branches/ipp-20130419/ippTools/share/chiptool_pendingcleanupimfile.sql
===================================================================
--- branches/eam_branches/ipp-20130419/ippTools/share/chiptool_pendingcleanupimfile.sql	(revision 35436)
+++ branches/eam_branches/ipp-20130419/ippTools/share/chiptool_pendingcleanupimfile.sql	(revision 35546)
@@ -13,6 +13,9 @@
     USING(chip_id)
 WHERE
-    ((chipRun.state = 'goto_cleaned' AND (chipProcessedImfile.data_state = 'full'
-                                       OR chipProcessedImfile.data_state = 'update') AND chipProcessedImfile.quality = 0)
+    ((chipRun.state = 'goto_cleaned'
+        AND (chipProcessedImfile.data_state = 'full'
+          OR chipProcessedImfile.data_state = 'update'
+          OR chipProcessedImfile.data_state = 'error_cleaned')
+        AND chipProcessedImfile.quality = 0)
 OR 
     (chipRun.state = 'goto_scrubbed' AND chipProcessedImfile.data_state != 'scrubbed')
Index: branches/eam_branches/ipp-20130419/ippTools/share/pxadmin_create_tables.sql
===================================================================
--- branches/eam_branches/ipp-20130419/ippTools/share/pxadmin_create_tables.sql	(revision 35436)
+++ branches/eam_branches/ipp-20130419/ippTools/share/pxadmin_create_tables.sql	(revision 35546)
@@ -1,3 +1,3 @@
-CREATE TABLE dbversion (
+eREATE TABLE dbversion (
     schema_version VARCHAR(64),
     updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP
@@ -2172,4 +2172,5 @@
     priority    INT,
     PRIMARY KEY(rel_id),
+    UNIQUE KEY(surveyID, release_name),
     KEY(release_name),
     KEY(release_state),
@@ -2196,4 +2197,5 @@
     PRIMARY KEY (relexp_id),
     FOREIGN KEY(rel_id) REFERENCES ippRelease(rel_id),
+    UNIQUE KEY(rel_id, exp_id),
     KEY (state),
     KEY (fault),
@@ -2224,6 +2226,6 @@
     time_stamp  DATETIME,
     PRIMARY KEY (relstack_id),
+    UNIQUE KEY (rel_id, tess_id, skycell_id, filter, stack_type, mjd_obs),
     KEY (tess_id, skycell_id),
-    KEY (rel_id, tess_id, skycell_id, filter, mjd_obs),
     KEY (stack_type),
     KEY (mjd_obs),
Index: branches/eam_branches/ipp-20130419/ippTools/share/releasetool_definerelstack.sql
===================================================================
--- branches/eam_branches/ipp-20130419/ippTools/share/releasetool_definerelstack.sql	(revision 35436)
+++ branches/eam_branches/ipp-20130419/ippTools/share/releasetool_definerelstack.sql	(revision 35546)
@@ -6,5 +6,5 @@
     stackRun.tess_id,
     stackRun.filter,
-    0 AS mjd_obs,
+    stackSumSkyfile.mjd_obs,
     0 AS zpt_obs,
     0 AS zpt_stdev
@@ -12,5 +12,13 @@
 FROM ippRelease
 JOIN stackRun
-LEFT JOIN relStack AS previousRelStack USING(rel_id, tess_id, skycell_id, filter)
-
+JOIN stackSumSkyfile using(stack_id)
+LEFT JOIN relStack AS previousRelStack 
+    ON previousRelStack.rel_id = ippRelease.rel_id
+    AND previousRelStack.tess_id = stackRun.tess_id 
+    AND previousRelStack.skycell_id = stackRun.skycell_id
+    AND previousRelStack.filter = stackRun.filter
+    -- JOIN hook %s
 WHERE previousRelStack.relstack_id IS NULL
+    AND stackRun.state ='full'
+    AND stackSumSkyfile.quality = 0
+    AND stackSumSkyfile.fault = 0
Index: branches/eam_branches/ipp-20130419/ippTools/share/releasetool_definerelstack_with_skycal.sql
===================================================================
--- branches/eam_branches/ipp-20130419/ippTools/share/releasetool_definerelstack_with_skycal.sql	(revision 35436)
+++ branches/eam_branches/ipp-20130419/ippTools/share/releasetool_definerelstack_with_skycal.sql	(revision 35546)
@@ -13,7 +13,14 @@
 JOIN stackRun
 JOIN stackSumSkyfile USING(stack_id)
-LEFT JOIN relStack AS previousRelStack USING(rel_id, tess_id, skycell_id, filter)
 JOIN skycalRun ON skycalRun.stack_id = stackRun.stack_id
 JOIN skycalResult ON skycalRun.skycal_id = skycalResult.skycal_id
+-- LEFT JOIN relStack AS previousRelStack USING(rel_id, tess_id, skycell_id, filter)
+LEFT JOIN relStack AS previousRelStack 
+    ON ippRelease.rel_id = previousRelStack.rel_id 
+    AND stackRun.tess_id = previousRelStack.tess_id 
+    AND stackRun.skycell_id = previousRelStack.skycell_id 
+    AND stackRun.filter = previousRelStack.filter
+-- JOIN Hook %s
 
 WHERE previousRelStack.relstack_id IS NULL
+    AND skycalRun.state = 'full'
Index: branches/eam_branches/ipp-20130419/ippTools/share/releasetool_listrelstack.sql
===================================================================
--- branches/eam_branches/ipp-20130419/ippTools/share/releasetool_listrelstack.sql	(revision 35436)
+++ branches/eam_branches/ipp-20130419/ippTools/share/releasetool_listrelstack.sql	(revision 35546)
@@ -7,4 +7,5 @@
     stackRun.state AS stack_state,
     stackRun.data_group AS stack_data_group,
+    skycalResult.fwhm_major,
     skycalResult.path_base AS skycal_path_base,
     skycalRun.data_group AS skycal_data_group,
Index: branches/eam_branches/ipp-20130419/ippTools/share/warptool_pendingcleanupskyfile.sql
===================================================================
--- branches/eam_branches/ipp-20130419/ippTools/share/warptool_pendingcleanupskyfile.sql	(revision 35436)
+++ branches/eam_branches/ipp-20130419/ippTools/share/warptool_pendingcleanupskyfile.sql	(revision 35546)
@@ -10,7 +10,9 @@
     USING(warp_id)
 WHERE
-   ((warpRun.state = 'goto_cleaned'  AND (warpSkyfile.data_state = 'full'
-                                      OR  warpSkyfile.data_state = 'update')
-    AND warpSkyfile.quality = 0)
+   ((warpRun.state = 'goto_cleaned'  
+       AND (warpSkyfile.data_state = 'full'
+          OR  warpSkyfile.data_state = 'error_cleaned'
+          OR  warpSkyfile.data_state = 'update')
+       AND warpSkyfile.quality = 0)
     OR
     (warpRun.state = 'goto_scrubbed' AND warpSkyfile.data_state != 'scrubbed')
