Changeset 20994
- Timestamp:
- Dec 15, 2008, 1:05:11 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
dbconfig/changes.txt (modified) (2 diffs)
-
tools/collapse_diffinputs.pl (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/dbconfig/changes.txt
r20973 r20994 742 742 ALTER TABLE diffInputSkyfile CHANGE COLUMN skycell_id skycell_id VARCHAR(64) AFTER diff_id; 743 743 744 -- WARNING WARNING745 -- If you have existing diff runs they must be converted746 747 -- run the script collapse_diffinputs.pl here.748 -- collapse_diffinputs.pl dbname dbuser dbpass dbhost749 750 DELETE FROM diffInputSkyfile where template = 1;751 752 ALTER TABLE diffInputSkyfile DROP PRIMARY KEY;753 ALTER TABLE diffInputSkyfile ADD PRIMARY KEY (diff_id, skycell_id);754 ALTER TABLE diffInputSkyfile DROP COLUMN template;755 744 756 745 ALTER TABLE diffInputSkyfile CHANGE COLUMN warp_id warp1 BIGINT; … … 758 747 ALTER TABLE diffInputSkyfile ADD COLUMN warp2 BIGINT AFTER stack1, ADD KEY(warp2); 759 748 ALTER TABLE diffInputSkyfile CHANGE COLUMN stack_id stack2 BIGINT AFTER warp2; 749 750 -- WARNING WARNING 751 -- If you have existing diff runs they must be converted 752 753 -- run the script collapse_diffinputs.pl here. 754 755 -- collapse_diffinputs.pl dbname dbuser dbpass dbhost 756 757 DELETE FROM diffInputSkyfile where template = 1; 758 759 ALTER TABLE diffInputSkyfile DROP PRIMARY KEY; 760 ALTER TABLE diffInputSkyfile ADD PRIMARY KEY (diff_id, skycell_id); 761 ALTER TABLE diffInputSkyfile DROP COLUMN template; 762 760 763 ALTER TABLE diffInputSkyfile ADD FOREIGN KEY (diff_id) REFERENCES diffRun(diff_id); 761 764 762 # need to check these763 765 ALTER TABLE diffInputSkyfile ADD FOREIGN KEY (warp1, skycell_id, tess_id) REFERENCES warpSkyfile(warp_id, skycell_id, tess_id); 764 766 ALTER TABLE diffInputSkyfile ADD FOREIGN KEY (warp2, skycell_id, tess_id) REFERENCES warpSkyfile(warp_id, skycell_id, tess_id); -
trunk/tools/collapse_diffinputs.pl
r20975 r20994 5 5 # From version 1.1.46 of the schema to 1.1.47 6 6 # 7 # Assumes that exp_id has been added to diffRun, but no other changes 8 # have been made 9 # 7 # Assumes that the changes up to the diffInputSkyfile columns have been 8 # made up to the place where it says that this script should be run 10 9 11 10 use strict; … … 27 26 28 27 # find all exposures in summitExp 29 my $query = "SELECT * FROM diffInputSkyfile where template = 1"; 28 # my $query = "SELECT * FROM diffInputSkyfile where template = 1"; 29 30 my $query = " 31 select 32 diff_id, 33 warp1, 34 stack1, 35 warp2, 36 stack2 37 FROM 38 (select 39 diff_id, 40 warp1 as warp1, 41 stack2 as stack1 42 from diffInputSkyfile 43 WHERE template = 0 44 ) as inputs 45 JOIN 46 (select 47 diff_id, 48 warp1 as warp2, 49 stack2 as stack2 50 from diffInputSkyfile 51 WHERE template = 1 52 ) as templates 53 USING (diff_id) 54 "; 30 55 31 56 my $stmt = $dbh->prepare($query); 32 57 $stmt->execute(); 33 58 34 my $sub_query .= "(SELECT exp_id FROM diffInputSkyfile JOIN warpRun USING(warp_id) join fakeRun using(fake_id) join camRun using(cam_id) join chipRun using(chip_id) where diff_id = ? )"; 59 60 my $sub_query .= "(SELECT exp_id FROM diffInputSkyfile JOIN warpRun on diffInputSkyfile.warp1 = warpRun.warp_id join fakeRun using(fake_id) join camRun using(cam_id) join chipRun using(chip_id) where diff_id = ? )"; 35 61 36 62 my $exp_query = "UPDATE diffRun SET exp_id = $sub_query where diff_id = ?"; … … 38 64 while (my $ref = $stmt->fetchrow_hashref()) { 39 65 my $diff_id = $ref->{diff_id}; 40 my $stack_id = $ref->{stack_id}; 66 my $warp1 = $ref->{warp1}; 67 my $warp2 = $ref->{warp2}; 68 my $stack1 = $ref->{stack1}; 69 my $stack2 = $ref->{stack2}; 41 70 42 # copy the stack_id to the row with template = 0 43 $dbh->do("UPDATE diffInputSkyfile SET stack_id = $stack_id where diff_id = $diff_id AND template = 0"); 71 # reorganizing columns puts warp1 and stack 1 correctly for template. 72 # set all of the stack and warp fields in the template = 0 input 73 # (the template = 1 row will be deleted) 74 if ($warp1 and $stack2) { 75 # usual case warp - stack 76 $dbh->do("UPDATE diffInputSkyfile SET stack2 = $stack2 where diff_id = $diff_id AND template = 0"); 77 } elsif ($stack1 and $stack2) { 78 # stack - stack 79 $dbh->do("UPDATE diffInputSkyfile SET stack1 = $stack1, stack2 = $stack2 where diff_id = $diff_id AND template = 0"); 80 } elsif ($warp1 and $warp2) { 81 # warp - warp 82 $dbh->do("UPDATE diffInputSkyfile SET warp2 = $warp2 where diff_id = $diff_id AND template = 0"); 83 } elsif ($stack1 and $warp2) { 84 # stack - warp 85 $dbh->do("UPDATE diffInputSkyfile SET stack1 = $stack1, warp2 = $warp2 where diff_id = $diff_id AND template = 0"); 86 } else { 87 die "unexpected input set for $diff_id"; 88 } 44 89 45 # set the exp_id for the diffRun46 90 # 47 my $rows = $dbh->do($exp_query, undef, $diff_id, $diff_id); 48 die "failed to update diffRun.exp_id for $diff_id" if ($rows != 1); 91 # set the exp_id for the diffRun if the input is a warp 92 # 93 if ($warp1) { 94 my $rows = $dbh->do($exp_query, undef, $diff_id, $diff_id); 95 die "failed to update diffRun.exp_id for $diff_id" if ($rows != 1); 96 } 49 97 } 50 98
Note:
See TracChangeset
for help on using the changeset viewer.
