IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20994


Ignore:
Timestamp:
Dec 15, 2008, 1:05:11 PM (17 years ago)
Author:
bills
Message:

update schema changes to handle the migration of all diff input/template
combinations

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/dbconfig/changes.txt

    r20973 r20994  
    742742ALTER TABLE diffInputSkyfile CHANGE COLUMN skycell_id skycell_id VARCHAR(64) AFTER diff_id;
    743743
    744 -- WARNING WARNING
    745 -- If you have existing diff runs they must be converted
    746 
    747 -- run the script collapse_diffinputs.pl here.
    748 --        collapse_diffinputs.pl dbname dbuser dbpass dbhost
    749 
    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;
    755744
    756745ALTER TABLE diffInputSkyfile CHANGE COLUMN warp_id warp1 BIGINT;
     
    758747ALTER TABLE diffInputSkyfile ADD COLUMN warp2 BIGINT AFTER stack1, ADD KEY(warp2);
    759748ALTER 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
     757DELETE FROM diffInputSkyfile where template = 1;
     758
     759ALTER TABLE diffInputSkyfile DROP PRIMARY KEY;
     760ALTER TABLE diffInputSkyfile ADD PRIMARY KEY (diff_id, skycell_id);
     761ALTER TABLE diffInputSkyfile DROP COLUMN template;
     762
    760763ALTER TABLE diffInputSkyfile ADD FOREIGN KEY (diff_id) REFERENCES diffRun(diff_id);
    761764
    762 # need to check these
    763765ALTER TABLE diffInputSkyfile ADD FOREIGN KEY (warp1, skycell_id, tess_id) REFERENCES warpSkyfile(warp_id, skycell_id, tess_id);
    764766ALTER 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  
    55# From version 1.1.46 of the schema to 1.1.47
    66#
    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
    109
    1110use strict;
     
    2726
    2827# find all exposures in summitExp
    29 my $query = "SELECT * FROM diffInputSkyfile where template = 1";
     28# my $query = "SELECT * FROM diffInputSkyfile where template = 1";
     29
     30my $query = "
     31select
     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";
    3055
    3156my $stmt = $dbh->prepare($query);
    3257$stmt->execute();
    3358
    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
     60my $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 = ? )";
    3561
    3662my $exp_query = "UPDATE diffRun SET exp_id = $sub_query where diff_id = ?";
     
    3864while (my $ref = $stmt->fetchrow_hashref()) {
    3965    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};
    4170
    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    }
    4489
    45     # set the exp_id for the diffRun
    4690    #
    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    }
    4997}
    5098
Note: See TracChangeset for help on using the changeset viewer.