Index: trunk/dbconfig/changes.txt
===================================================================
--- trunk/dbconfig/changes.txt	(revision 19620)
+++ trunk/dbconfig/changes.txt	(revision 19622)
@@ -472,19 +472,16 @@
 
 ALTER TABLE detResidImfile add column ref_det_id bigint after iteration;
-ALTER TABLE detResidImfile add column ref_iter int after iteration;
-
-ALTER TABLE detResidImfile add column ref_det_id bigint after iteration;
-ALTER TABLE detResidImfile add column ref_iter int after iteration;
+ALTER TABLE detResidImfile add column ref_iter int after ref_det_id;
 
 ALTER TABLE detRun change column parent ref_det_id bigint;
 ALTER TABLE detRun add column ref_iter int after ref_det_id;
 
--- XXX need to change the foreign key constraints on detResidImfile:
--- This
---    FOREIGN KEY (det_id, iteration)
---    REFERENCES  detNormalizedExp(det_id, iteration)
--- Becomes:
---    FOREIGN KEY (ref_det_id, ref_iter)
---    REFERENCES  detNormalizedExp(det_id, iteration)
-
--- XXX Need to population ref_det_id with the contents of det_id for detRun.mode == 'master'
+-- populate ref_det_id and ref_iter 
+UPDATE detResidImfile SET ref_det_id = det_id, ref_iter = iteration;
+
+-- Next we drop the old constraint and add the new one
+ALTER TABLE detResidImfile DROP FOREIGN KEY detResidImfile_ibfk_3;
+ALTER TABLE detResidImfile add FOREIGN KEY  (ref_det_id, ref_iter)
+    REFERENCES  detNormalizedExp(det_id, iteration);
+
+
