Index: trunk/ippToPsps/jython/ipptopspsdb.py
===================================================================
--- trunk/ippToPsps/jython/ipptopspsdb.py	(revision 31807)
+++ trunk/ippToPsps/jython/ipptopspsdb.py	(revision 31808)
@@ -23,8 +23,9 @@
     Creates a new batch
     '''
-    def createNewBatch(self, batchType, survey, dvoDb, datastoreProduct):
+    def createNewBatch(self, batchType, stageID, survey, dvoDb, datastoreProduct):
 
         sql = "INSERT INTO batch ( \
                batch_type, \
+               stage_id, \
                survey, \
                dvo_db, \
@@ -32,4 +33,5 @@
                ) VALUES ( \
                '" + batchType + "', \
+               " + str(stageID) + ", \
                '" + survey + "', \
                '" + dvoDb + "', \
@@ -91,10 +93,9 @@
     Have we already processed and published this batch?
     '''
-    def alreadyProcessed(self, table, col, value):
+    def alreadyProcessed(self, stage_id):
 
-        sql = "SELECT COUNT(*) FROM \
-               " + table + " \
-               JOIN batch USING(batch_id) \
-               WHERE " + col + " = " + str(value) + " \
+        sql = "SELECT COUNT(*) \
+               FROM batch \
+               WHERE stage_id = " + str(stage_id) + " \
                AND processed \
                AND loaded_to_datastore"
@@ -104,5 +105,5 @@
             rs.first()
             if rs.getInt(1) > 0: 
-                self.logger.error("Batch with "+col+" = "+str(value)+" has already been processed and published to datastore")
+                self.logger.error("Batch with stage_id = "+str(stage_id) + " has already been processed and published to datastore")
                 return True
             else: 
@@ -133,9 +134,8 @@
     Inserts some stack metadata for this batch ID
     '''
-    def insertStackMeta(self, batchID, skyID, stackID, filter, stackType):
+    def insertStackMeta(self, batchID, stackID, filter, stackType):
 
         sql = "INSERT INTO stack ( \
                batch_id \
-               ,sky_id \
                ,stack_id \
                ,filter \
@@ -143,5 +143,4 @@
                ) VALUES ( \
                " + str(batchID) + " \
-               ," + str(skyID) + " \
                ," + str(stackID) + " \
                ,'" + filter + "' \
