Changeset 28534 for branches/pap/ippToPsps/scripts/createDb.pl
- Timestamp:
- Jun 28, 2010, 8:11:04 PM (16 years ago)
- Location:
- branches/pap
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippToPsps/scripts/createDb.pl (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap
- Property svn:mergeinfo changed
/trunk (added) merged: 28500,28502,28507,28509-28512,28514,28516-28518,28520,28522,28524-28532
- Property svn:mergeinfo changed
-
branches/pap/ippToPsps/scripts/createDb.pl
r28206 r28534 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 ####################################################################################### … … 50 61 primary key (revision) 51 62 ); 52 SQL53 $query->execute;54 55 $query = $db->prepare(<<SQL);56 INSERT INTO revision (revision) VALUES (1);57 63 SQL 58 64 $query->execute; … … 77 83 $query->execute; 78 84 85 setRevision(1); 86 87 } 88 89 ####################################################################################### 90 # 91 # Create revision 2 of the database 92 # 93 ####################################################################################### 94 sub 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 102 SQL 103 $query->execute; 104 105 setRevision(2); 106 } 107 108 ####################################################################################### 109 # 110 # Create revision 3 of the database 111 # 112 ####################################################################################### 113 sub 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 121 SQL 122 $query->execute; 123 124 setRevision(3); 125 } 126 127 128 ####################################################################################### 129 # 130 # Sets current revision of ippToPsps database 131 # 132 ####################################################################################### 133 sub setRevision { 134 my ($revision) = @_; 135 136 my $query = $db->prepare(<<SQL); 137 INSERT INTO revision (revision) VALUES ($revision); 138 SQL 139 $query->execute; 79 140 } 80 141 … … 82 143 # 83 144 # Gets current revision of ippToPsps database 145 # 146 ####################################################################################### 147 sub 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; 156 SQL 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 84 166 # 85 167 ####################################################################################### … … 99 181 my $count = $query->fetchrow_array(); 100 182 101 printf( "* Table '$table' %s\n", $count ? "exists" : "does not exist");102 103 183 return $count; 104 184 }
Note:
See TracChangeset
for help on using the changeset viewer.
