IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 28, 2010, 8:11:04 PM (16 years ago)
Author:
Paul Price
Message:

Merging trunk in preparation for merging branch to trunk.

Location:
branches/pap
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/ippToPsps/scripts/createDb.pl

    r28206 r28534  
    2525print "* Connected to '$dbname' on 'dbserver'\n";
    2626
    27 if (!doesTableExist("revision")) {
    28     createRevision_1();
     27my $currentRevision = -1;
     28
     29my $latestRevision = 3;
     30    print "* Latest revision = $latestRevision\n";
     31
     32while ($currentRevision != $latestRevision) {
     33
     34    $currentRevision = getRevision();
     35    print "* Current revision = $currentRevision\n";
     36
     37    if ($currentRevision == 0) {createRevision_1();}
     38    elsif ($currentRevision == 1) {createRevision_2();}
     39    elsif ($currentRevision == 2) {createRevision_3();}
     40
    2941}
    30 
    31 
    3242$db->disconnect();
    3343print "* Disconnected from '$dbname' on 'dbserver'\n";
    3444print "*\n*******************************************************************************\n\n";
     45
    3546
    3647#######################################################################################
     
    5061            primary key (revision)
    5162            );
    52 SQL
    53         $query->execute;
    54 
    55     $query = $db->prepare(<<SQL);
    56     INSERT INTO revision (revision) VALUES (1);
    5763SQL
    5864        $query->execute;
     
    7783    $query->execute;
    7884
     85setRevision(1);
     86
     87}
     88
     89#######################################################################################
     90#
     91# Create revision 2 of the database
     92#
     93#######################################################################################
     94sub createRevision_2 {
     95
     96    print "* Creating revision 2 of '$dbname'\n";
     97
     98        my $query = $db->prepare(<<SQL);
     99
     100        ALTER TABLE batches
     101        ADD COLUMN merged TINYINT DEFAULT 0
     102SQL
     103    $query->execute;
     104
     105setRevision(2);
     106}
     107
     108#######################################################################################
     109#
     110# Create revision 3 of the database
     111#
     112#######################################################################################
     113sub createRevision_3 {
     114
     115    print "* Creating revision 3 of '$dbname'\n";
     116
     117        my $query = $db->prepare(<<SQL);
     118
     119        ALTER TABLE batches
     120        ADD COLUMN total_detections BIGINT DEFAULT 0
     121SQL
     122    $query->execute;
     123
     124setRevision(3);
     125}
     126
     127
     128#######################################################################################
     129#
     130# Sets current revision of ippToPsps database
     131#
     132#######################################################################################
     133sub setRevision {
     134    my ($revision) = @_;
     135
     136    my $query = $db->prepare(<<SQL);
     137    INSERT INTO revision (revision) VALUES ($revision);
     138SQL
     139        $query->execute;
    79140}
    80141
     
    82143#
    83144# Gets current revision of ippToPsps database
     145#
     146#######################################################################################
     147sub getRevision {
     148
     149    if (!doesTableExist("revision")) {return 0;}
     150
     151    my $query = $db->prepare(<<SQL);
     152
     153    SELECT revision
     154        FROM revision
     155        ORDER BY revision DESC LIMIT 1;
     156SQL
     157   $query->execute;
     158   my @row = $query->fetchrow_array();
     159
     160   return $row[0];
     161}
     162
     163#######################################################################################
     164#
     165# Checks whether a certain table exists
    84166#
    85167#######################################################################################
     
    99181    my $count = $query->fetchrow_array();
    100182
    101     printf( "* Table '$table' %s\n", $count ? "exists" : "does not exist");
    102 
    103183    return $count;
    104184}
Note: See TracChangeset for help on using the changeset viewer.