- Timestamp:
- Jul 30, 2010, 9:31:50 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100621/ippToPsps/scripts/createDb.pl
r28206 r28794 25 25 print "* Connected to '$dbname' on 'dbserver'\n"; 26 26 27 if (!doesTableExist("revision")) { 28 createRevision_1(); 27 my $currentRevision = -1; 28 29 my $latestRevision = 3; 30 print "* Latest revision = $latestRevision\n"; 31 32 while ($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 29 41 } 30 31 32 42 $db->disconnect(); 33 43 print "* Disconnected from '$dbname' on 'dbserver'\n"; 34 44 print "*\n*******************************************************************************\n\n"; 45 35 46 36 47 ####################################################################################### … … 45 56 my $query = $db->prepare(<<SQL); 46 57 CREATE TABLE revision ( 47 48 58 revision INT, 49 59 created TIMESTAMP DEFAULT NOW(), … … 54 64 55 65 $query = $db->prepare(<<SQL); 56 INSERT INTO revision (revision) VALUES (1);57 SQL58 $query->execute;59 60 $query = $db->prepare(<<SQL);61 66 62 67 CREATE TABLE batches ( 63 64 68 batch_id BIGINT NOT NULL, 65 69 exp_id BIGINT NOT NULL, … … 77 81 $query->execute; 78 82 83 setRevision(1); 84 85 } 86 87 ####################################################################################### 88 # 89 # Create revision 2 of the database 90 # 91 ####################################################################################### 92 sub 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 100 SQL 101 $query->execute; 102 103 setRevision(2); 104 } 105 106 ####################################################################################### 107 # 108 # Create revision 3 of the database 109 # 110 ####################################################################################### 111 sub 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 119 SQL 120 $query->execute; 121 122 setRevision(3); 123 } 124 125 126 ####################################################################################### 127 # 128 # Sets current revision of ippToPsps database 129 # 130 ####################################################################################### 131 sub setRevision { 132 my ($revision) = @_; 133 134 my $query = $db->prepare(<<SQL); 135 INSERT INTO revision (revision) VALUES ($revision); 136 SQL 137 $query->execute; 79 138 } 80 139 … … 82 141 # 83 142 # Gets current revision of ippToPsps database 143 # 144 ####################################################################################### 145 sub 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; 154 SQL 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 84 164 # 85 165 ####################################################################################### … … 99 179 my $count = $query->fetchrow_array(); 100 180 101 printf( "* Table '$table' %s\n", $count ? "exists" : "does not exist");102 103 181 return $count; 104 182 }
Note:
See TracChangeset
for help on using the changeset viewer.
