IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 30, 2010, 9:31:50 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100621/ippToPsps/scripts/createDb.pl

    r28206 r28794  
    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#######################################################################################
     
    4556    my $query = $db->prepare(<<SQL);
    4657    CREATE TABLE revision (
    47 
    4858            revision INT,
    4959            created TIMESTAMP DEFAULT NOW(),
     
    5464
    5565    $query = $db->prepare(<<SQL);
    56     INSERT INTO revision (revision) VALUES (1);
    57 SQL
    58         $query->execute;
    59 
    60     $query = $db->prepare(<<SQL);
    6166
    6267    CREATE TABLE batches (
    63 
    6468            batch_id BIGINT NOT NULL,
    6569            exp_id BIGINT NOT NULL,
     
    7781    $query->execute;
    7882
     83setRevision(1);
     84
     85}
     86
     87#######################################################################################
     88#
     89# Create revision 2 of the database
     90#
     91#######################################################################################
     92sub createRevision_2 {
     93
     94    print "* Creating revision 2 of '$dbname'\n";
     95
     96        my $query = $db->prepare(<<SQL);
     97
     98        ALTER TABLE batches
     99        ADD COLUMN merged TINYINT DEFAULT 0
     100SQL
     101    $query->execute;
     102
     103setRevision(2);
     104}
     105
     106#######################################################################################
     107#
     108# Create revision 3 of the database
     109#
     110#######################################################################################
     111sub createRevision_3 {
     112
     113    print "* Creating revision 3 of '$dbname'\n";
     114
     115        my $query = $db->prepare(<<SQL);
     116
     117        ALTER TABLE batches
     118        ADD COLUMN total_detections BIGINT DEFAULT 0
     119SQL
     120    $query->execute;
     121
     122setRevision(3);
     123}
     124
     125
     126#######################################################################################
     127#
     128# Sets current revision of ippToPsps database
     129#
     130#######################################################################################
     131sub setRevision {
     132    my ($revision) = @_;
     133
     134    my $query = $db->prepare(<<SQL);
     135    INSERT INTO revision (revision) VALUES ($revision);
     136SQL
     137        $query->execute;
    79138}
    80139
     
    82141#
    83142# Gets current revision of ippToPsps database
     143#
     144#######################################################################################
     145sub getRevision {
     146
     147    if (!doesTableExist("revision")) {return 0;}
     148
     149    my $query = $db->prepare(<<SQL);
     150
     151    SELECT revision
     152        FROM revision
     153        ORDER BY revision DESC LIMIT 1;
     154SQL
     155   $query->execute;
     156   my @row = $query->fetchrow_array();
     157
     158   return $row[0];
     159}
     160
     161#######################################################################################
     162#
     163# Checks whether a certain table exists
    84164#
    85165#######################################################################################
     
    99179    my $count = $query->fetchrow_array();
    100180
    101     printf( "* Table '$table' %s\n", $count ? "exists" : "does not exist");
    102 
    103181    return $count;
    104182}
Note: See TracChangeset for help on using the changeset viewer.