r4500 bugfix: (this message was lost) was shown in:
[racktables] / wwwroot / inc / upgrade.php
CommitLineData
6dc745d2 1<?php
fbbb74fb 2
90b96ff6
DO
3$relnotes = array
4(
5ae6d365
DO
5 '0.17.0' => <<<ENDOFTEXT
6LDAP options have been moved to LDAP_options array. This means, that if you were
7using LDAP authentication for users in version 0.16.x, it will break right after
8upgrade to 0.17.0. To get things working again, adjust existing secret.php file
9according to secret-sample.php file provided with 0.17.0 release.
10
11This release is the first to take advantage of the foreign key support
12provided by the InnoDB storage engine in MySQL. The installer and
13upgrader scripts check for InnoDB support and cannot complete without it.
14If you have trouble, the first step is to make sure the 'skip-innodb'
15option in my.cnf is commented out.
16
17Another change is the addition of support for file uploads. Files are stored
18in the database. There are several settings in php.ini which you may need to modify:
19 file_uploads - needs to be On
20 upload_max_filesize - max size for uploaded files
21 post_max_size - max size of all form data submitted via POST (including files)
22
23User accounts used to have 'enabled' flag, which allowed individual blocking and
24unblocking of each. This flag was dropped in favor of existing mean of access
25setup (RackCode). An unconditional denying rule is automatically added into RackCode
26for such blocked account, so the effective security policy remains the same.
27ENDOFTEXT
28,
1679ddbd
DO
29 '0.18.2' => <<<ENDOFTEXT
30RackTables from its version 0.18.0 and later is not compatible with
31RHEL/CentOS (at least with versions up to 5.5) Linux distributions
32in their default installation. There are yet options to work around that:
331. Install RackTables on a server with a different distribution/OS.
342. Request Linux distribution vendor to fix the bug with PCRE.
353. Repair your RHEL/CentOS installation yourself by fixing its PCRE
36RPM as explained here: http://bugs.centos.org/view.php?id=3252
37ENDOFTEXT
9fb6900d
DO
38,
39 '0.19.0' => <<<ENDOFTEXT
841a5b54
DO
40The files, which are intended for the httpd (web-server) directory, are
41now in the "wwwroot" directory of the tar.gz archive. Files outside of
42that directory are not directly intended for httpd environment and should
43not be copied to the server.
9fb6900d 44
8489d2af
DO
45This release incorporates ObjectLog functionality, which used to be
46available as a separate plugin. For the best results it is advised to
47disable (through local.php) external ObjectLog plugin permanently before
48the new version is installed. All previously accumulated ObjectLog records
49will be available through the updated standard interface.
50
841a5b54
DO
51RackTables is now using PHP JSON extension which is included in the PHP
52core since 5.2.0.
53
54The barcode attribute was removed. The upgrade script attempts to
55preserve the data by moving it to either the 'OEM S/N 1' attribute or to
56a Log entry. You should backup your database beforehand anyway.
9fb6900d 57ENDOFTEXT
36efe434
DO
58,
59 '0.19.2' => <<<ENDOFTEXT
60This release is different in filesystem layout. The "gateways" directory
4f5aea8a
AA
61has been moved from "wwwroot" directory. This improves security a bit.
62You can also separate your local settings and add-ons from the core RackTables code.
63To do that, put a single index.php file into the DocumentRoot of your http server:
36efe434 64
4f5aea8a
AA
65<?php
66\$racktables_confdir='/directory/where/your/secret.php/and/local.php/files/are/stored';
67require '/directory_where_you_extracted_racktables_distro/wwwroot/index.php';
68?>
69
70No more files are needed to be available directly over the HTTP.
71Full list of filesystem paths which could be specified in custom index.php or secret.php:
72 \$racktables_gwdir: path to the gateways directory;
73 \$racktables_staticdir: path to the directory containing 'pix', 'js', 'css' dirs;
74 \$racktables_confdir: path where secret.php and local.php are located. It is not
75 recommended to define it in secret.php, cause only the path to
76 local.php will be affected;
77 \$path_to_secret_php: Ignore \$racktables_confdir when locating secret.php and use
78 the specified path;
79 \$path_to_local_php: idem for local.php.
36efe434 80ENDOFTEXT
5ae6d365 81,
90b96ff6
DO
82);
83
fbbb74fb
DO
84// At the moment we assume, that for any two releases we can
85// sequentally execute all batches, that separate them, and
86// nothing will break. If this changes one day, the function
87// below will have to generate smarter upgrade paths, while
88// the upper layer will remain the same.
89// Returning an empty array means that no upgrade is necessary.
4114697d 90// Returning NULL indicates an error.
fbbb74fb
DO
91function getDBUpgradePath ($v1, $v2)
92{
a6f83a72
DO
93 $versionhistory = array
94 (
b3f866fc 95 '0.16.4',
64347dcf 96 '0.16.5',
90b96ff6 97 '0.16.6',
30d0a2a3 98 '0.17.0',
4563cecb 99 '0.17.1',
7b1a3a72 100 '0.17.2',
9e51318b 101 '0.17.3',
958ac06d 102 '0.17.4',
9f572fb5 103 '0.17.5',
63811a09 104 '0.17.6',
026a79ee 105 '0.17.7',
3540d15c 106 '0.17.8',
1e81ad97 107 '0.17.9',
f32167d2 108 '0.17.10',
4a4a5440 109 '0.17.11',
9013f05b 110 '0.18.0',
425fd829 111 '0.18.1',
298d2375 112 '0.18.2',
f6d1a7cc 113 '0.18.3',
1c5b7c84 114 '0.18.4',
92ee2b01 115 '0.18.5',
2f5e4db9 116 '0.18.6',
9fb6900d 117 '0.18.7',
16825cc8 118 '0.19.0',
1d5dd3a1 119 '0.19.1',
0abae5fb 120 '0.19.2',
03d86c03 121 '0.19.3',
18a89570 122 '0.20.0',
a6f83a72 123 );
120e9ddd
DO
124 if (!in_array ($v1, $versionhistory) or !in_array ($v2, $versionhistory))
125 return NULL;
fbbb74fb 126 $skip = TRUE;
4114697d 127 $path = NULL;
154a42e5
DO
128 // foreach() below cannot handle this specific case
129 if ($v1 == $v2)
130 return array();
fbbb74fb
DO
131 // Now collect all versions > $v1 and <= $v2
132 foreach ($versionhistory as $v)
133 {
4114697d 134 if ($skip and $v == $v1)
fbbb74fb
DO
135 {
136 $skip = FALSE;
4114697d 137 $path = array();
fbbb74fb
DO
138 continue;
139 }
140 if ($skip)
141 continue;
142 $path[] = $v;
143 if ($v == $v2)
144 break;
145 }
146 return $path;
147}
148
90b96ff6
DO
149// Upgrade batches are named exactly as the release where they first appear.
150// That is simple, but seems sufficient for beginning.
fbbb74fb
DO
151function executeUpgradeBatch ($batchid)
152{
153 $query = array();
ca3d68bd 154 global $dbxlink;
fbbb74fb
DO
155 switch ($batchid)
156 {
64347dcf
DO
157 case '0.16.5':
158 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('IPV4_TREE_SHOW_USAGE','yes','string','no','no','Show address usage in IPv4 tree')";
159 $query[] = "update Config set varvalue = '0.16.5' where varname = 'DB_VERSION'";
160 break;
90b96ff6
DO
161 case '0.16.6':
162 $query[] = "update Config set varvalue = '0.16.6' where varname = 'DB_VERSION'";
163 break;
30d0a2a3 164 case '0.17.0':
e1ae3fb4
AD
165 // create tables for storing files (requires InnoDB support)
166 if (!isInnoDBSupported ())
167 {
964b0388 168 showError ("Cannot upgrade because InnoDB tables are not supported by your MySQL server. See the README for details.", __FUNCTION__);
f3c50166 169 die;
e1ae3fb4 170 }
f76c4197
DY
171
172 $query[] = "alter table Chapter change chapter_no id int(10) unsigned NOT NULL auto_increment";
173 $query[] = "alter table Chapter change chapter_name name char(128) NOT NULL";
174 $query[] = "alter table Chapter drop key chapter_name";
175 $query[] = "alter table Chapter add UNIQUE KEY name (name)";
176 $query[] = "alter table Attribute change attr_id id int(10) unsigned NOT NULL auto_increment";
177 $query[] = "alter table Attribute change attr_type type enum('string','uint','float','dict') default NULL";
178 $query[] = "alter table Attribute change attr_name name char(64) default NULL";
179 $query[] = "alter table Attribute drop key attr_name";
180 $query[] = "alter table Attribute add UNIQUE KEY name (name)";
181 $query[] = "alter table AttributeMap change chapter_no chapter_id int(10) unsigned NOT NULL";
182 $query[] = "alter table Dictionary change chapter_no chapter_id int(10) unsigned NOT NULL";
3fb336f6 183 // Only after the above call it is Ok to use reloadDictionary()
ca3d68bd 184 $query = array_merge ($query, reloadDictionary ($batchid));
f3c50166 185 // schema changes for file management
e1ae3fb4
AD
186 $query[] = "
187CREATE TABLE `File` (
188 `id` int(10) unsigned NOT NULL auto_increment,
189 `name` char(255) NOT NULL,
190 `type` char(255) NOT NULL,
191 `size` int(10) unsigned NOT NULL,
192 `ctime` datetime NOT NULL,
193 `mtime` datetime NOT NULL,
194 `atime` datetime NOT NULL,
195 `contents` longblob NOT NULL,
196 `comment` text,
13edfa1c
AD
197 PRIMARY KEY (`id`),
198 UNIQUE KEY `name` (`name`)
e1ae3fb4
AD
199) ENGINE=InnoDB";
200 $query[] = "
201CREATE TABLE `FileLink` (
202 `id` int(10) unsigned NOT NULL auto_increment,
203 `file_id` int(10) unsigned NOT NULL,
204 `entity_type` enum('ipv4net','ipv4rspool','ipv4vs','object','rack','user') NOT NULL default 'object',
205 `entity_id` int(10) NOT NULL,
206 PRIMARY KEY (`id`),
af721881 207 UNIQUE KEY `FileLink-unique` (`file_id`,`entity_type`,`entity_id`),
e1ae3fb4
AD
208 KEY `FileLink-file_id` (`file_id`),
209 CONSTRAINT `FileLink-File_fkey` FOREIGN KEY (`file_id`) REFERENCES `File` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
210) ENGINE=InnoDB";
211 $query[] = "ALTER TABLE TagStorage MODIFY COLUMN target_realm enum('file','ipv4net','ipv4rspool','ipv4vs','object','rack','user') NOT NULL default 'object'";
f3c50166 212
f76c4197 213 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (24,'no','network security models')";
9730d09f 214 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (25,'no','wireless models')";
f76c4197
DY
215 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,1,0)";
216 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,2,24)";
217 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,3,0)";
218 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,5,0)";
219 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,14,0)";
220 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,16,0)";
221 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,17,0)";
222 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,18,0)";
223 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,20,0)";
224 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,21,0)";
225 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,22,0)";
226 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,24,0)";
9730d09f
DO
227 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (965,1,0)";
228 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (965,3,0)";
229 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (965,2,25)";
706ce117
DO
230 $query[] = 'alter table IPBonds rename to IPv4Allocation';
231 $query[] = 'alter table PortForwarding rename to IPv4NAT';
232 $query[] = 'alter table IPRanges rename to IPv4Network';
233 $query[] = 'alter table IPAddress rename to IPv4Address';
234 $query[] = 'alter table IPLoadBalancer rename to IPv4LB';
4114697d 235 $query[] = 'alter table IPRSPool rename to IPv4RSPool';
706ce117 236 $query[] = 'alter table IPRealServer rename to IPv4RS';
4114697d 237 $query[] = 'alter table IPVirtualService rename to IPv4VS';
120e9ddd
DO
238 $query[] = "alter table TagStorage change column target_realm entity_realm enum('file','ipv4net','ipv4vs','ipv4rspool','object','rack','user') NOT NULL default 'object'";
239 $query[] = 'alter table TagStorage change column target_id entity_id int(10) unsigned NOT NULL';
240 $query[] = 'alter table TagStorage drop key entity_tag';
241 $query[] = 'alter table TagStorage drop key target_id';
242 $query[] = 'alter table TagStorage add UNIQUE KEY `entity_tag` (`entity_realm`,`entity_id`,`tag_id`)';
243 $query[] = 'alter table TagStorage add KEY `entity_id` (`entity_id`)';
37e59768
DO
244 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_TEXT_MAXCHARS','10240','uint','yes','no','Max chars for text file preview')";
245 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_TEXT_ROWS','25','uint','yes','no','Rows for text file preview')";
246 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_TEXT_COLS','80','uint','yes','no','Columns for text file preview')";
247 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_IMAGE_MAXPXS','320','uint','yes','no','Max pixels per axis for image file preview')";
f3d274bf 248 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('VENDOR_SIEVE','','string','yes','no','Vendor sieve configuration')";
073ed463
DO
249 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('IPV4LB_LISTSRC','{\$typeid_4}','string','yes','no','List source: IPv4 load balancers')";
250 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('IPV4OBJ_LISTSRC','{\$typeid_4} or {\$typeid_7} or {\$typeid_8} or {\$typeid_12} or {\$typeid_445} or {\$typeid_447}','string','yes','no','List source: IPv4-enabled objects')";
251 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('IPV4NAT_LISTSRC','{\$typeid_4} or {\$typeid_7} or {\$typeid_8}','string','yes','no','List source: IPv4 NAT performers')";
252 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('ASSETWARN_LISTSRC','{\$typeid_4} or {\$typeid_7} or {\$typeid_8}','string','yes','no','List source: object, for which asset tag should be set')";
253 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('NAMEWARN_LISTSRC','{\$typeid_4} or {\$typeid_7} or {\$typeid_8}','string','yes','no','List source: object, for which common name should be set')";
f5883ec1 254 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('RACKS_PER_ROW','12','unit','yes','no','Racks per row')";
590e1281 255 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_PREDICATE_SIEVE','','string','yes','no','Predicate sieve regex(7)')";
5496c89f
DO
256 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_DEFAULT_ANDOR','or','string','no','no','Default list filter boolean operation (or/and)')";
257 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_SUGGEST_ANDOR','yes','string','no','no','Suggest and/or selector in list filter')";
258 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_SUGGEST_TAGS','yes','string','no','no','Suggest tags in list filter')";
259 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_SUGGEST_PREDICATES','yes','string','no','no','Suggest predicates in list filter')";
260 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_SUGGEST_EXTRA','no','string','no','no','Suggest extra expression in list filter')";
529eac25
DO
261 $query[] = "delete from Config where varname = 'USER_AUTH_SRC'";
262 $query[] = "delete from Config where varname = 'COOKIE_TTL'";
263 $query[] = "delete from Config where varname = 'rtwidth_0'";
264 $query[] = "delete from Config where varname = 'rtwidth_1'";
265 $query[] = "delete from Config where varname = 'rtwidth_2'";
c6bc0ac5
DO
266 $query[] = "delete from Config where varname = 'NAMEFUL_OBJTYPES'";
267 $query[] = "delete from Config where varname = 'REQUIRE_ASSET_TAG_FOR'";
268 $query[] = "delete from Config where varname = 'IPV4_PERFORMERS'";
269 $query[] = "delete from Config where varname = 'NATV4_PERFORMERS'";
dbb33805 270 $query[] = "alter table TagTree add column valid_realm set('file','ipv4net','ipv4vs','ipv4rspool','object','rack','user') not null default 'file,ipv4net,ipv4vs,ipv4rspool,object,rack,user' after parent_id";
a476909e
DO
271 $result = $dbxlink->query ("select user_id, user_name, user_realname from UserAccount where user_enabled = 'no'");
272 while ($row = $result->fetch (PDO::FETCH_ASSOC))
273 $query[] = "update Script set script_text = concat('deny {\$userid_${row['user_id']}} # ${row['user_name']} (${row['user_realname']})\n', script_text) where script_name = 'RackCode'";
274 $query[] = "update Script set script_text = NULL where script_name = 'RackCodeCache'";
275 unset ($result);
79b8ad1e 276 $query[] = "alter table UserAccount drop column user_enabled";
f76c4197 277
10bac82a
DY
278 $query[] = "CREATE TABLE RackRow ( id int(10) unsigned NOT NULL auto_increment, name char(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM";
279
9f14a7ef
DY
280 $result = $dbxlink->query ("select dict_key, dict_value from Dictionary where chapter_no = 3");
281 while($row = $result->fetch(PDO::FETCH_NUM))
10bac82a 282 $query[] = "insert into RackRow set id=${row[0]}, name='${row[1]}'";
ee286837 283 unset ($result);
f76c4197 284 $query[] = "delete from Dictionary where chapter_id = 3";
c4d0dc30 285 $query[] = "delete from Chapter where id = 3";
9133d2c5
DO
286 $query[] = "
287CREATE TABLE `LDAPCache` (
288 `presented_username` char(64) NOT NULL,
289 `successful_hash` char(40) NOT NULL,
290 `first_success` timestamp NOT NULL default CURRENT_TIMESTAMP,
291 `last_retry` timestamp NOT NULL default '0000-00-00 00:00:00',
292 `displayed_name` char(128) default NULL,
293 `memberof` text,
294 UNIQUE KEY `presented_username` (`presented_username`),
295 KEY `scanidx` (`presented_username`,`successful_hash`)
296) ENGINE=InnoDB;";
3827da34 297 $query[] = "alter table UserAccount modify column user_password_hash char(40) NULL";
aa9a0fb4
DO
298 $query[] = 'ALTER TABLE Rack DROP COLUMN deleted';
299 $query[] = 'ALTER TABLE RackHistory DROP COLUMN deleted';
300 $query[] = 'ALTER TABLE RackObject DROP COLUMN deleted';
301 $query[] = 'ALTER TABLE RackObjectHistory DROP COLUMN deleted';
2fb9d280
DO
302 // Can't be added straight due to many duplicates, even in "dictbase" data.
303 $result = $dbxlink->query ('SELECT type1, type2, count(*) - 1 as excess FROM PortCompat GROUP BY type1, type2 HAVING excess > 0');
304 while ($row = $result->fetch (PDO::FETCH_ASSOC))
305 $query[] = "DELETE FROM PortCompat WHERE type1 = ${row['type1']} AND type2 = ${row['type2']} limit ${row['excess']}";
306 unset ($result);
307 $query[] = 'ALTER TABLE PortCompat DROP KEY type1';
67d8a969 308 $query[] = 'ALTER TABLE PortCompat ADD UNIQUE `type1_2` (type1, type2)';
f76c4197
DY
309 $query[] = "UPDATE Config SET varvalue = '0.17.0' WHERE varname = 'DB_VERSION'";
310
b3f866fc 311 break;
4563cecb 312 case '0.17.1':
8b200a9c 313 $query[] = "ALTER TABLE Dictionary DROP KEY `chap_to_key`";
ca3d68bd 314 $query = array_merge ($query, reloadDictionary ($batchid));
4563cecb
DO
315 // Token set has changed, so the cache isn't valid any more.
316 $query[] = "UPDATE Script SET script_text = NULL WHERE script_name = 'RackCodeCache'";
317 $query[] = "UPDATE Config SET varvalue = '0.17.1' WHERE varname = 'DB_VERSION'";
7d4ea62b 318 break;
7b1a3a72 319 case '0.17.2':
7b1a3a72 320 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (26,'no','fibre channel switch models')";
ca3d68bd 321 $query = array_merge ($query, reloadDictionary ($batchid));
7c537f33 322 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1055,2,26)";
49b605d9 323 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('DEFAULT_SNMP_COMMUNITY','public','string','no','no','Default SNMP Community string')";
29c3a4d8
DO
324 // wipe irrelevant records (ticket:250)
325 $query[] = "DELETE FROM TagStorage WHERE entity_realm = 'file' AND entity_id NOT IN (SELECT id FROM File)";
f06fe423 326 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('IPV4_ENABLE_KNIGHT','yes','string','no','no','Enable IPv4 knight feature')";
99ab184f 327 $query[] = "ALTER TABLE IPv4Network ADD COLUMN comment text AFTER name";
5163cd3a 328 $query[] = "ALTER TABLE Port ADD INDEX comment (reservation_comment)";
029a14bc
DO
329 $query[] = "ALTER TABLE Port DROP KEY l2address"; // UNIQUE
330 $query[] = "ALTER TABLE Port ADD KEY (l2address)"; // not UNIQUE
948666cc
DO
331 $query[] = "ALTER TABLE Port DROP KEY object_id";
332 $query[] = "ALTER TABLE Port ADD UNIQUE KEY per_object (object_id, name, type)";
74aee2dc
DO
333 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (20,1083)";
334 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (21,1083)";
335 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1077,1077)";
336 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1083,20)";
337 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1083,21)";
338 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1083,1083)";
1c4830dc 339 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1087,1087)";
50e02490
DO
340 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (27,'no','PDU models')";
341 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (2,2,27)";
7b1a3a72
AD
342 $query[] = "UPDATE Config SET varvalue = '0.17.2' WHERE varname = 'DB_VERSION'";
343 break;
9e51318b
DO
344 case '0.17.3':
345 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('TAGS_TOPLIST_SIZE','50','uint','yes','no','Tags top list size')";
346 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('TAGS_QUICKLIST_SIZE','20','uint','no','no','Tags quick list size')";
347 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('TAGS_QUICKLIST_THRESHOLD','50','uint','yes','no','Tags quick list threshold')";
87601bbc 348 $query[] = "ALTER TABLE AttributeMap MODIFY COLUMN chapter_id int(10) unsigned NULL";
7028a42c 349 $query[] = "UPDATE AttributeMap SET chapter_id = NULL WHERE attr_id IN (SELECT id FROM Attribute WHERE type != 'dict')";
a013838b
DO
350 // ticket:239
351 $query[] = 'UPDATE AttributeValue SET uint_value = 1018 WHERE uint_value = 731 AND attr_id IN (SELECT attr_id FROM AttributeMap WHERE chapter_id = 12)';
352 $query[] = 'DELETE FROM Dictionary WHERE dict_key = 731';
084aca6c
DO
353 $query = array_merge ($query, reloadDictionary ($batchid));
354 $query[] = "UPDATE Config SET vartype='uint' WHERE varname='RACKS_PER_ROW'";
f44fdef9 355 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('ENABLE_MULTIPORT_FORM','no','string','no','no','Enable \"Add/update multiple ports\" form')";
9e51318b
DO
356 $query[] = "UPDATE Config SET varvalue = '0.17.3' WHERE varname = 'DB_VERSION'";
357 break;
958ac06d
DO
358 case '0.17.4':
359 $query[] = "ALTER TABLE Link ENGINE=InnoDB";
360 $query[] = "ALTER TABLE Port ENGINE=InnoDB";
4d87feaf
DO
361 $query[] = "ALTER TABLE IPv4RS ENGINE=InnoDB";
362 $query[] = "ALTER TABLE IPv4RSPool ENGINE=InnoDB";
cafd4cf3
DO
363 $query[] = "ALTER TABLE AttributeValue ENGINE=InnoDB";
364 $query[] = "ALTER TABLE RackObject ENGINE=InnoDB";
365 $query[] = "ALTER TABLE IPv4NAT ENGINE=InnoDB";
366 $query[] = "ALTER TABLE IPv4LB ENGINE=InnoDB";
367 $query[] = "ALTER TABLE IPv4VS ENGINE=InnoDB";
4d87feaf 368 $query[] = "DELETE FROM IPv4RS WHERE rspool_id NOT IN (SELECT id FROM IPv4RSPool)";
958ac06d 369 $query[] = "ALTER TABLE Link ADD CONSTRAINT `Link-FK-b` FOREIGN KEY (portb) REFERENCES Port (id)";
cafd4cf3 370 $query[] = "ALTER TABLE Link ADD CONSTRAINT `Link-FK-a` FOREIGN KEY (porta) REFERENCES Port (id)";
4d87feaf 371 $query[] = "ALTER TABLE IPv4RS ADD CONSTRAINT `IPv4RS-FK` FOREIGN KEY (rspool_id) REFERENCES IPv4RSPool (id) ON DELETE CASCADE";
cafd4cf3
DO
372 $query[] = "ALTER TABLE AttributeValue ADD CONSTRAINT `AttributeValue-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id)";
373 $query[] = "ALTER TABLE IPv4NAT ADD CONSTRAINT `IPv4NAT-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id)";
374 $query[] = "ALTER TABLE Port ADD CONSTRAINT `Port-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id)";
375 $query[] = "ALTER TABLE IPv4LB ADD CONSTRAINT `IPv4LB-FK-rspool_id` FOREIGN KEY (rspool_id) REFERENCES IPv4RSPool (id)";
376 $query[] = "ALTER TABLE IPv4LB ADD CONSTRAINT `IPv4LB-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id)";
377 $query[] = "ALTER TABLE IPv4LB ADD CONSTRAINT `IPv4LB-FK-vs_id` FOREIGN KEY (vs_id) REFERENCES IPv4VS (id)";
e49d8a77 378 $query = array_merge ($query, reloadDictionary ($batchid));
958ac06d
DO
379 $query[] = "UPDATE Config SET varvalue = '0.17.4' WHERE varname = 'DB_VERSION'";
380 break;
9f572fb5
DO
381 case '0.17.5':
382 $query[] = "ALTER TABLE TagTree ENGINE=InnoDB";
383 $query[] = "ALTER TABLE TagStorage ENGINE=InnoDB";
384 $query[] = "ALTER TABLE TagStorage ADD CONSTRAINT `TagStorage-FK-tag_id` FOREIGN KEY (tag_id) REFERENCES TagTree (id)";
385 $query[] = "ALTER TABLE TagTree ADD CONSTRAINT `TagTree-K-parent_id` FOREIGN KEY (parent_id) REFERENCES TagTree (id)";
2400d7ec
DO
386 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (21,1195)';
387 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (22,1196)';
388 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (23,1196)';
389 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (20,1195)';
390 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (25,1202)';
391 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (26,1202)';
392 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (27,1204)';
393 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (28,1204)';
394 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1083,1195)';
395 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1084,1084)';
396 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1195,20)';
397 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1195,21)';
398 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1195,1083)';
399 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1195,1195)';
400 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1196,22)';
401 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1196,23)';
402 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1196,1196)';
403 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1197,1197)';
404 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1198,1199)';
405 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1199,1198)';
406 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1200,1200)';
407 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1201,1201)';
408 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1202,25)';
409 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1202,26)';
410 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1202,1202)';
411 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1203,1203)';
412 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1204,27)';
413 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1204,28)';
414 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1204,1204)';
415 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1205,1205)';
416 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1206,1207)';
417 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1207,1206)';
93a83f51 418 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1316,1316)';
bdc91a5c
DO
419 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (16, 1322)';
420 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1322, 16)';
421 $query[] = 'DELETE FROM PortCompat WHERE type1 = 16 AND type2 = 16';
2400d7ec
DO
422 for ($i = 1209; $i <= 1300; $i++)
423 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (${i}, ${i})";
d9b88ea0 424 $query[] = "
09d6afa4 425CREATE TABLE `PortInnerInterface` (
9173281a 426 `id` int(10) unsigned NOT NULL,
d9b88ea0
DO
427 `iif_name` char(16) NOT NULL,
428 PRIMARY KEY (`id`),
9173281a 429 UNIQUE KEY `iif_name` (`iif_name`)
d9b88ea0 430) ENGINE=InnoDB";
2400d7ec
DO
431 $query[] = "INSERT INTO `PortInnerInterface` VALUES (1,'hardwired')";
432 $query[] = "INSERT INTO `PortInnerInterface` VALUES (2,'SFP-100')";
433 $query[] = "INSERT INTO `PortInnerInterface` VALUES (3,'GBIC')";
434 $query[] = "INSERT INTO `PortInnerInterface` VALUES (4,'SFP-1000')";
435 $query[] = "INSERT INTO `PortInnerInterface` VALUES (5,'XENPAK')";
436 $query[] = "INSERT INTO `PortInnerInterface` VALUES (6,'X2')";
437 $query[] = "INSERT INTO `PortInnerInterface` VALUES (7,'XPAK')";
438 $query[] = "INSERT INTO `PortInnerInterface` VALUES (8,'XFP')";
439 $query[] = "INSERT INTO `PortInnerInterface` VALUES (9,'SFP+')";
d9b88ea0 440 $query[] = "
09d6afa4 441CREATE TABLE `PortInterfaceCompat` (
d9b88ea0
DO
442 `iif_id` int(10) unsigned NOT NULL,
443 `oif_id` int(10) unsigned NOT NULL,
444 UNIQUE KEY `pair` (`iif_id`,`oif_id`),
2400d7ec 445 CONSTRAINT `PortInterfaceCompat-FK-iif_id` FOREIGN KEY (`iif_id`) REFERENCES `PortInnerInterface` (`id`)
d9b88ea0 446) ENGINE=InnoDB";
c76cfa0d
DO
447 $query[] = "ALTER TABLE Port ADD COLUMN iif_id int unsigned NOT NULL AFTER name"; // will set iif_id to 0
448 $query[] = "UPDATE Port SET iif_id = 2 WHERE type = 1208";
449 $query[] = "UPDATE Port SET iif_id = 3 WHERE type = 1078";
450 $query[] = "UPDATE Port SET iif_id = 4 WHERE type = 1077";
451 $query[] = "UPDATE Port SET iif_id = 5 WHERE type = 1079";
452 $query[] = "UPDATE Port SET iif_id = 6 WHERE type = 1080";
453 $query[] = "UPDATE Port SET iif_id = 7 WHERE type = 1081";
454 $query[] = "UPDATE Port SET iif_id = 8 WHERE type = 1082";
455 $query[] = "UPDATE Port SET iif_id = 9 WHERE type = 1084";
456 $query[] = "UPDATE Port SET iif_id = 1 WHERE iif_id = 0";
08aa3467
DO
457 $query[] = 'ALTER TABLE Port ADD UNIQUE `object_iif_oif_name` (object_id, iif_id, type, name)';
458 $query[] = 'ALTER TABLE Port DROP KEY `per_object`';
2400d7ec
DO
459 $base1000 = array (24, 34, 1202, 1203, 1204, 1205, 1206, 1207);
460 $base10000 = array (30, 35, 36, 37, 38, 39, 40);
461 $PICdata = array
462 (
bdc91a5c 463 1 => array (16, 19, 24, 29, 31, 33, 446, 681, 682, 1322),
2400d7ec
DO
464 2 => array (1208, 1195, 1196, 1197, 1198, 1199, 1200, 1201),
465 3 => array_merge (array (1078), $base1000),
466 4 => array_merge (array (1077), $base1000),
467 5 => array_merge (array (1079), $base10000),
468 6 => array_merge (array (1080), $base10000),
469 7 => array_merge (array (1081), $base10000),
470 8 => array_merge (array (1082), $base10000),
471 9 => array_merge (array (1084), $base10000),
472 );
473 // make sure all IIF/OIF pairs referenced from Port exist in PortInterfaceCompat before enabling FK
474 // iif_id doesn't exist at this point
475 $result = $dbxlink->query ('SELECT DISTINCT type FROM Port WHERE type NOT IN (1208, 1078, 1077, 1079, 1080, 1081, 1082, 1084)');
476 while ($row = $result->fetch (PDO::FETCH_ASSOC))
477 if (FALSE === array_search ($row['type'], $PICdata[1]))
478 array_push ($PICdata[1], $row['type']);
479 unset ($result);
480 foreach ($PICdata as $iif_id => $oif_ids)
481 foreach ($oif_ids as $oif_id)
482 $query[] = "INSERT INTO PortInterfaceCompat (iif_id, oif_id) VALUES (${iif_id}, ${oif_id})";
c76cfa0d 483 $query[] = "ALTER TABLE Port ADD CONSTRAINT `Port-FK-iif-oif` FOREIGN KEY (`iif_id`, `type`) REFERENCES `PortInterfaceCompat` (`iif_id`, `oif_id`)";
bdc91a5c 484 $query[] = 'UPDATE Port SET type = 1322 WHERE type = 16 AND (SELECT objtype_id FROM RackObject WHERE id = object_id) IN (2, 12)';
2400d7ec
DO
485 $query = array_merge ($query, reloadDictionary ($batchid));
486 $query[] = "DELETE FROM Config WHERE varname = 'default_port_type'";
487 $query[] = "INSERT INTO Config VALUES ('DEFAULT_PORT_IIF_ID','1','uint','no','no','Default port inner interface ID')";
488 $query[] = "INSERT INTO Config VALUES ('DEFAULT_PORT_OIF_IDS','1=24; 3=1078; 4=1077; 5=1079; 6=1080; 8=1082; 9=1084','string','no','no','Default port outer interface IDs')";
4a47d34b 489 $query[] = "INSERT INTO Config VALUES ('IPV4_TREE_RTR_AS_CELL','yes','string','no','no','Show full router info for each network in IPv4 tree view')";
93a83f51 490 $query[] = "UPDATE Chapter SET name = 'PortOuterInterface' WHERE id = 2";
fbcbb4ee
DO
491 // remap refs to duplicate records, which will be discarded (ticket:286)
492 $query[] = 'UPDATE AttributeValue SET uint_value = 147 WHERE uint_value = 1020 AND attr_id = 2';
493 $query[] = 'UPDATE AttributeValue SET uint_value = 377 WHERE uint_value = 1021 AND attr_id = 2';
e8ab58e8 494 $query[] = 'INSERT INTO AttributeMap (objtype_id, attr_id) VALUES (2, 1), (2, 3), (2, 5)';
9f572fb5
DO
495 $query[] = "UPDATE Config SET varvalue = '0.17.5' WHERE varname = 'DB_VERSION'";
496 break;
63811a09
DO
497 case '0.17.6':
498 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (28,'no','Voice/video hardware')";
499 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1323,1,NULL)";
500 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1323,2,28)";
501 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1323,3,NULL)";
502 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1323,5,NULL)";
cd3775e9 503 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PROXIMITY_RANGE','0','uint','yes','no','Proximity range (0 is current rack only)')";
5c3bc8de 504 $query = array_merge ($query, reloadDictionary ($batchid));
63811a09
DO
505 $query[] = "UPDATE Config SET varvalue = '0.17.6' WHERE varname = 'DB_VERSION'";
506 break;
026a79ee
DO
507 case '0.17.7':
508 $query[] = "UPDATE Config SET varvalue = '0.17.7' WHERE varname = 'DB_VERSION'";
509 break;
3540d15c 510 case '0.17.8':
1e81ad97
DO
511 $query = array_merge ($query, reloadDictionary ($batchid));
512 $query[] = "ALTER TABLE TagTree DROP COLUMN valid_realm";
513 $query[] = "UPDATE Config SET varvalue = '0.17.8' WHERE varname = 'DB_VERSION'";
514 break;
515 case '0.17.9':
45833307 516 $query[] = "ALTER table Config add `is_userdefined` enum('yes','no') NOT NULL default 'no' AFTER `is_hidden`";
3540d15c
DY
517 $query[] = "
518CREATE TABLE `UserConfig` (
519 `varname` char(32) NOT NULL,
520 `varvalue` char(255) NOT NULL,
521 `user` char(64) NOT NULL,
522 UNIQUE KEY `user_varname` (`user`,`varname`)
523) TYPE=InnoDB";
1e81ad97
DO
524 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname IN
525(
526'MASSCOUNT',
527'MAXSELSIZE',
528'ROW_SCALE',
529'PORTS_PER_ROW',
530'IPV4_ADDRS_PER_PAGE',
531'DEFAULT_RACK_HEIGHT',
532'DEFAULT_SLB_VS_PORT',
533'DEFAULT_SLB_RS_PORT',
534'DETECT_URLS',
535'RACK_PRESELECT_THRESHOLD',
536'DEFAULT_IPV4_RS_INSERVICE',
537'DEFAULT_OBJECT_TYPE',
538'SHOW_EXPLICIT_TAGS',
539'SHOW_IMPLICIT_TAGS',
540'SHOW_AUTOMATIC_TAGS',
541'IPV4_AUTO_RELEASE',
542'SHOW_LAST_TAB',
543'EXT_IPV4_VIEW',
544'TREE_THRESHOLD',
545'ADDNEW_AT_TOP',
546'IPV4_TREE_SHOW_USAGE',
547'PREVIEW_TEXT_MAXCHARS',
548'PREVIEW_TEXT_ROWS',
549'PREVIEW_TEXT_COLS',
550'PREVIEW_IMAGE_MAXPXS',
551'VENDOR_SIEVE',
552'RACKS_PER_ROW'
553)";
9013f05b
DO
554 $query[] = "UPDATE Config SET varvalue = '0.17.9' WHERE varname = 'DB_VERSION'";
555 break;
f32167d2
DO
556 case '0.17.10':
557 $query = array_merge ($query, reloadDictionary ($batchid));
4368cc45 558 $query[] = "ALTER TABLE MountOperation ADD KEY (object_id)";
2926b1cb 559 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('STATIC_FILTER','yes','string','no','no','yes','Enable Filter Caching');";
f32167d2 560 $query[] = "UPDATE Config SET varvalue = '0.17.10' WHERE varname = 'DB_VERSION'";
d80036ba 561 break;
a1fc539a
RF
562 case '0.17.11':
563 $query = array_merge ($query, reloadDictionary ($batchid));
564 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('ENABLE_BULKPORT_FORM','yes','string','no','no','yes','Enable \"Bulk Port\" form');";
0f353a95 565 $query[] = "DELETE AttributeValue FROM AttributeValue JOIN Attribute where AttributeValue.attr_id = Attribute.id AND Attribute.type = 'dict' AND AttributeValue.uint_value = 0";
a1fc539a 566 $query[] = "UPDATE Config SET varvalue = '0.17.11' WHERE varname = 'DB_VERSION'";
59e0658a 567 break;
9013f05b 568 case '0.18.0':
ad9da675 569 $query = array_merge ($query, reloadDictionary ($batchid));
8bb69a06
DO
570 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('VLANSWITCH_LISTSRC', '', 'string', 'yes', 'no', 'yes', 'List of VLAN running switches')";
571 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('VLANIPV4NET_LISTSRC', '', 'string', 'yes', 'no', 'yes', 'List of VLAN-based IPv4 networks')";
572 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('DEFAULT_VDOM_ID','','uint','yes','no','yes','Default VLAN domain ID')";
573 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('DEFAULT_VST_ID','','uint','yes','no','yes','Default VLAN switch template ID')";
37cb9e18
DO
574 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('8021Q_DEPLOY_MINAGE','300','uint','no','no','no','802.1Q deploy minimum age')";
575 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('8021Q_DEPLOY_MAXAGE','3600','uint','no','no','no','802.1Q deploy maximum age')";
576 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('8021Q_DEPLOY_RETRY','10800','uint','no','no','no','802.1Q deploy retry timer')";
407ed7bb 577 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('8021Q_WRI_AFTER_CONFT','no','string','no','no','no','802.1Q: save device configuration after deploy')";
4492050b 578 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('8021Q_INSTANT_DEPLOY','no','string','no','no','yes','802.1Q: instant deploy')";
97c0a54e 579 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('IPV4_TREE_SHOW_VLAN','yes','string','no','no','yes','Show VLAN for each network in IPv4 tree')";
1768cc35 580 $query[] = "ALTER TABLE IPv4Network ENGINE=InnoDB";
22fdebff
DO
581 $query[] = "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0";
582 $query[] = "
583CREATE TABLE `CachedPAV` (
584 `object_id` int(10) unsigned NOT NULL,
585 `port_name` char(255) NOT NULL,
586 `vlan_id` int(10) unsigned NOT NULL default '0',
587 PRIMARY KEY (`object_id`,`port_name`,`vlan_id`),
588 KEY `vlan_id` (`vlan_id`),
589 CONSTRAINT `CachedPAV-FK-object-port` FOREIGN KEY (`object_id`, `port_name`) REFERENCES `CachedPVM` (`object_id`, `port_name`) ON DELETE CASCADE,
590 CONSTRAINT `CachedPAV-FK-vlan_id` FOREIGN KEY (`vlan_id`) REFERENCES `VLANValidID` (`vlan_id`)
591) ENGINE=InnoDB
592";
593 $query[] = "
594CREATE TABLE `CachedPNV` (
595 `object_id` int(10) unsigned NOT NULL,
596 `port_name` char(255) NOT NULL,
597 `vlan_id` int(10) unsigned NOT NULL default '0',
598 PRIMARY KEY (`object_id`,`port_name`,`vlan_id`),
599 UNIQUE KEY `port_id` (`object_id`,`port_name`),
600 CONSTRAINT `CachedPNV-FK-compound` FOREIGN KEY (`object_id`, `port_name`, `vlan_id`) REFERENCES `CachedPAV` (`object_id`, `port_name`, `vlan_id`) ON DELETE CASCADE
601) ENGINE=InnoDB
602";
603 $query[] = "
604CREATE TABLE `CachedPVM` (
605 `object_id` int(10) unsigned NOT NULL,
606 `port_name` char(255) NOT NULL,
607 `vlan_mode` enum('access','trunk') NOT NULL default 'access',
608 PRIMARY KEY (`object_id`,`port_name`),
609 CONSTRAINT `CachedPVM-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE
610) ENGINE=InnoDB
611";
612 $query[] = "
613CREATE TABLE `PortAllowedVLAN` (
614 `object_id` int(10) unsigned NOT NULL,
615 `port_name` char(255) NOT NULL,
616 `vlan_id` int(10) unsigned NOT NULL default '0',
617 PRIMARY KEY (`object_id`,`port_name`,`vlan_id`),
618 KEY `vlan_id` (`vlan_id`),
619 CONSTRAINT `PortAllowedVLAN-FK-object-port` FOREIGN KEY (`object_id`, `port_name`) REFERENCES `PortVLANMode` (`object_id`, `port_name`) ON DELETE CASCADE,
620 CONSTRAINT `PortAllowedVLAN-FK-vlan_id` FOREIGN KEY (`vlan_id`) REFERENCES `VLANValidID` (`vlan_id`)
621) ENGINE=InnoDB
622";
623 $query[] = "
624CREATE TABLE `PortNativeVLAN` (
625 `object_id` int(10) unsigned NOT NULL,
626 `port_name` char(255) NOT NULL,
627 `vlan_id` int(10) unsigned NOT NULL default '0',
628 PRIMARY KEY (`object_id`,`port_name`,`vlan_id`),
629 UNIQUE KEY `port_id` (`object_id`,`port_name`),
630 CONSTRAINT `PortNativeVLAN-FK-compound` FOREIGN KEY (`object_id`, `port_name`, `vlan_id`) REFERENCES `PortAllowedVLAN` (`object_id`, `port_name`, `vlan_id`) ON DELETE CASCADE
631) ENGINE=InnoDB
632";
633 $query[] = "
634CREATE TABLE `PortVLANMode` (
635 `object_id` int(10) unsigned NOT NULL,
636 `port_name` char(255) NOT NULL,
637 `vlan_mode` enum('access','trunk') NOT NULL default 'access',
638 PRIMARY KEY (`object_id`,`port_name`),
639 CONSTRAINT `PortVLANMode-FK-object-port` FOREIGN KEY (`object_id`, `port_name`) REFERENCES `CachedPVM` (`object_id`, `port_name`)
640) ENGINE=InnoDB
641";
642 $query[] = "
643CREATE TABLE `VLANDescription` (
644 `domain_id` int(10) unsigned NOT NULL,
645 `vlan_id` int(10) unsigned NOT NULL default '0',
646 `vlan_type` enum('ondemand','compulsory','alien') NOT NULL default 'ondemand',
647 `vlan_descr` char(255) default NULL,
648 PRIMARY KEY (`domain_id`,`vlan_id`),
649 KEY `vlan_id` (`vlan_id`),
219da133 650 CONSTRAINT `VLANDescription-FK-domain_id` FOREIGN KEY (`domain_id`) REFERENCES `VLANDomain` (`id`) ON DELETE CASCADE,
22fdebff
DO
651 CONSTRAINT `VLANDescription-FK-vlan_id` FOREIGN KEY (`vlan_id`) REFERENCES `VLANValidID` (`vlan_id`)
652) ENGINE=InnoDB
653";
654 $query[] = "
655CREATE TABLE `VLANDomain` (
656 `id` int(10) unsigned NOT NULL auto_increment,
657 `description` char(255) default NULL,
658 PRIMARY KEY (`id`),
659 UNIQUE KEY `description` (`description`)
660) ENGINE=InnoDB
661";
662 $query[] = "
663CREATE TABLE `VLANIPv4` (
664 `domain_id` int(10) unsigned NOT NULL,
665 `vlan_id` int(10) unsigned NOT NULL,
666 `ipv4net_id` int(10) unsigned NOT NULL,
667 UNIQUE KEY `network-domain` (`ipv4net_id`,`domain_id`),
668 KEY `VLANIPv4-FK-compound` (`domain_id`,`vlan_id`),
669 CONSTRAINT `VLANIPv4-FK-compound` FOREIGN KEY (`domain_id`, `vlan_id`) REFERENCES `VLANDescription` (`domain_id`, `vlan_id`) ON DELETE CASCADE,
670 CONSTRAINT `VLANIPv4-FK-ipv4net_id` FOREIGN KEY (`ipv4net_id`) REFERENCES `IPv4Network` (`id`) ON DELETE CASCADE
671) ENGINE=InnoDB
672";
673 $query[] = "
674CREATE TABLE `VLANSTRule` (
675 `vst_id` int(10) unsigned NOT NULL,
676 `rule_no` int(10) unsigned NOT NULL,
677 `port_pcre` char(255) NOT NULL,
678 `port_role` enum('access','trunk','uplink','downlink','none') NOT NULL default 'none',
679 `wrt_vlans` char(255) default NULL,
680 `description` char(255) default NULL,
681 UNIQUE KEY `vst-rule` (`vst_id`,`rule_no`),
682 CONSTRAINT `VLANSTRule-FK-vst_id` FOREIGN KEY (`vst_id`) REFERENCES `VLANSwitchTemplate` (`id`) ON DELETE CASCADE
683) ENGINE=InnoDB
684";
685 $query[] = "
686CREATE TABLE `VLANSwitch` (
687 `object_id` int(10) unsigned NOT NULL,
688 `domain_id` int(10) unsigned NOT NULL,
689 `template_id` int(10) unsigned NOT NULL,
690 `mutex_rev` int(10) unsigned NOT NULL default '0',
691 `out_of_sync` enum('yes','no') NOT NULL default 'yes',
692 `last_errno` int(10) unsigned NOT NULL default '0',
693 `last_change` timestamp NOT NULL default '0000-00-00 00:00:00',
694 `last_push_started` timestamp NOT NULL default '0000-00-00 00:00:00',
695 `last_push_finished` timestamp NOT NULL default '0000-00-00 00:00:00',
696 `last_error_ts` timestamp NOT NULL default '0000-00-00 00:00:00',
697 UNIQUE KEY `object_id` (`object_id`),
698 KEY `domain_id` (`domain_id`),
699 KEY `template_id` (`template_id`),
700 KEY `out_of_sync` (`out_of_sync`),
701 KEY `last_errno` (`last_errno`),
702 CONSTRAINT `VLANSwitch-FK-domain_id` FOREIGN KEY (`domain_id`) REFERENCES `VLANDomain` (`id`),
703 CONSTRAINT `VLANSwitch-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`),
704 CONSTRAINT `VLANSwitch-FK-template_id` FOREIGN KEY (`template_id`) REFERENCES `VLANSwitchTemplate` (`id`)
705) ENGINE=InnoDB
706";
707 $query[] = "
708CREATE TABLE `VLANSwitchTemplate` (
709 `id` int(10) unsigned NOT NULL auto_increment,
710 `max_local_vlans` int(10) unsigned default NULL,
711 `description` char(255) default NULL,
712 PRIMARY KEY (`id`),
713 UNIQUE KEY `description` (`description`)
714) ENGINE=InnoDB
715";
716 $query[] = "
717CREATE TABLE `VLANValidID` (
718 `vlan_id` int(10) unsigned NOT NULL default '1',
719 PRIMARY KEY (`vlan_id`)
720) ENGINE=InnoDB
721";
722 $query[] = "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS";
fa11e5c7 723 for ($i = 1; $i <= 4094; $i++)
a401a680 724 $query[] = "INSERT INTO VLANValidID (vlan_id) VALUES (${i})";
9013f05b 725 $query[] = "UPDATE Config SET varvalue = '0.18.0' WHERE varname = 'DB_VERSION'";
08d1ef24 726 break;
425fd829
DO
727 case '0.18.1':
728 $query = array_merge ($query, reloadDictionary ($batchid));
b6978d62
DO
729 $query[] = "ALTER TABLE Atom ENGINE=InnoDB";
730 $query[] = "ALTER TABLE AttributeMap ENGINE=InnoDB";
731 $query[] = "ALTER TABLE Config ENGINE=InnoDB";
732 $query[] = "ALTER TABLE IPv4Address ENGINE=InnoDB";
733 $query[] = "ALTER TABLE IPv4Allocation ENGINE=InnoDB";
734 $query[] = "ALTER TABLE Molecule ENGINE=InnoDB";
735 $query[] = "ALTER TABLE MountOperation ENGINE=InnoDB";
736 $query[] = "ALTER TABLE PortCompat ENGINE=InnoDB";
737 $query[] = "ALTER TABLE Rack ENGINE=InnoDB";
738 $query[] = "ALTER TABLE RackHistory ENGINE=InnoDB";
739 $query[] = "ALTER TABLE RackObjectHistory ENGINE=InnoDB";
740 $query[] = "ALTER TABLE RackRow ENGINE=InnoDB";
741 $query[] = "ALTER TABLE RackSpace ENGINE=InnoDB";
742 $query[] = "ALTER TABLE Script ENGINE=InnoDB";
735f169f
DO
743 $query[] = "ALTER TABLE AttributeValue DROP FOREIGN KEY `AttributeValue-FK-object_id`";
744 $query[] = "ALTER TABLE AttributeValue ADD CONSTRAINT `AttributeValue-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE";
55267f67
DO
745 $query[] = "ALTER TABLE RackObjectHistory ADD KEY (id)";
746 $query[] = "ALTER TABLE RackObjectHistory ADD CONSTRAINT `RackObjectHistory-FK-object_id` FOREIGN KEY (id) REFERENCES `RackObject` (`id`) ON DELETE CASCADE";
f3552988 747 $query[] = "ALTER TABLE MountOperation ADD CONSTRAINT `MountOperation-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id) ON DELETE CASCADE";
f7cec175 748 $query[] = "ALTER TABLE RackSpace ADD CONSTRAINT `RackSpace-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id) ON DELETE CASCADE";
1bcfe894
DO
749 $query[] = "ALTER TABLE Link DROP FOREIGN KEY `Link-FK-a`";
750 $query[] = "ALTER TABLE Link ADD CONSTRAINT `Link-FK-a` FOREIGN KEY (`porta`) REFERENCES `Port` (`id`) ON DELETE CASCADE";
751 $query[] = "ALTER TABLE Link DROP FOREIGN KEY `Link-FK-b`";
752 $query[] = "ALTER TABLE Link ADD CONSTRAINT `Link-FK-b` FOREIGN KEY (`portb`) REFERENCES `Port` (`id`) ON DELETE CASCADE";
753 $query[] = "ALTER TABLE Port DROP FOREIGN KEY `Port-FK-object_id`";
754 $query[] = "ALTER TABLE Port ADD CONSTRAINT `Port-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE";
e7787961
DO
755 $query[] = "ALTER TABLE AttributeMap MODIFY `chapter_id` int(10) unsigned default NULL";
756 $query[] = "ALTER TABLE IPv4Address MODIFY `ip` int(10) unsigned NOT NULL default '0'";
757 $query[] = "ALTER TABLE IPv4Address MODIFY `name` char(255) NOT NULL default ''";
758 $query[] = "ALTER TABLE IPv4Allocation MODIFY `object_id` int(10) unsigned NOT NULL default '0'";
759 $query[] = "ALTER TABLE IPv4Allocation MODIFY `ip` int(10) unsigned NOT NULL default '0'";
760 $query[] = "ALTER TABLE IPv4Allocation MODIFY `name` char(255) NOT NULL default ''";
761 $query[] = "ALTER TABLE IPv4NAT MODIFY `object_id` int(10) unsigned NOT NULL default '0'";
762 $query[] = "ALTER TABLE IPv4NAT MODIFY `proto` enum('TCP','UDP') NOT NULL default 'TCP'";
763 $query[] = "ALTER TABLE IPv4NAT MODIFY `localip` int(10) unsigned NOT NULL default '0'";
764 $query[] = "ALTER TABLE IPv4NAT MODIFY `localport` smallint(5) unsigned NOT NULL default '0'";
765 $query[] = "ALTER TABLE IPv4NAT MODIFY `remoteip` int(10) unsigned NOT NULL default '0'";
766 $query[] = "ALTER TABLE IPv4NAT MODIFY `remoteport` smallint(5) unsigned NOT NULL default '0'";
767 $query[] = "ALTER TABLE IPv4Network MODIFY `ip` int(10) unsigned NOT NULL default '0'";
768 $query[] = "ALTER TABLE IPv4Network MODIFY `mask` int(10) unsigned NOT NULL default '0'";
769 $query[] = "ALTER TABLE Link MODIFY `porta` int(10) unsigned NOT NULL default '0'";
770 $query[] = "ALTER TABLE Link MODIFY `portb` int(10) unsigned NOT NULL default '0'";
771 $query[] = "ALTER TABLE MountOperation MODIFY `object_id` int(10) unsigned NOT NULL default '0'";
772 $query[] = "ALTER TABLE MountOperation MODIFY `ctime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP";
773 $query[] = "ALTER TABLE Port MODIFY `object_id` int(10) unsigned NOT NULL default '0'";
774 $query[] = "ALTER TABLE Port MODIFY `name` char(255) NOT NULL default ''";
775 $query[] = "ALTER TABLE Port MODIFY `type` int(10) unsigned NOT NULL default '0'";
776 $query[] = "ALTER TABLE PortCompat MODIFY `type1` int(10) unsigned NOT NULL default '0'";
777 $query[] = "ALTER TABLE PortCompat MODIFY `type2` int(10) unsigned NOT NULL default '0'";
778 $query[] = "ALTER TABLE RackHistory MODIFY `ctime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP";
779 $query[] = "ALTER TABLE RackObjectHistory MODIFY `ctime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP";
780 $query[] = "ALTER TABLE TagStorage MODIFY `tag_id` int(10) unsigned NOT NULL default '0'";
781 $query[] = "ALTER TABLE UserAccount MODIFY `user_name` char(64) NOT NULL default ''";
425fd829
DO
782 $query[] = "UPDATE Config SET varvalue = '0.18.1' WHERE varname = 'DB_VERSION'";
783 break;
298d2375
DO
784 case '0.18.2':
785 $query = array_merge ($query, reloadDictionary ($batchid));
786 $query[] = "ALTER TABLE Rack ADD CONSTRAINT `Rack-FK-row_id` FOREIGN KEY (row_id) REFERENCES RackRow (id)";
b504972c 787 $query[] = "ALTER TABLE RackRow ADD UNIQUE KEY `name` (name)";
b49a479e
DO
788 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('CDP_RUNNERS_LISTSRC', '', 'string', 'yes', 'no', 'no', 'List of devices running CDP')";
789 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('LLDP_RUNNERS_LISTSRC', '', 'string', 'yes', 'no', 'no', 'List of devices running LLDP')";
10eadad9 790 $query[] = "UPDATE Config SET varvalue = '0.18.2' WHERE varname = 'DB_VERSION'";
298d2375 791 break;
2582446d 792 case '0.18.3':
0891c041 793 $query = array_merge ($query, reloadDictionary ($batchid));
2582446d 794 $query[] = "UPDATE Config SET varname='8021Q_WRI_AFTER_CONFT_LISTSRC', varvalue='false', description='802.1Q: save device configuration after deploy (RackCode)' WHERE varname='8021Q_WRI_AFTER_CONFT'";
0328f6d6 795 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('HNDP_RUNNERS_LISTSRC', '', 'string', 'yes', 'no', 'no', 'List of devices running HNDP (RackCode)')";
2582446d
DO
796 $query[] = "UPDATE Config SET varvalue = '0.18.3' WHERE varname = 'DB_VERSION'";
797 break;
3a387b0d
DO
798 case '0.18.4':
799 $query = array_merge ($query, reloadDictionary ($batchid));
ec523868 800 $query[] = "ALTER TABLE VLANSTRule MODIFY port_role enum('access','trunk','anymode','uplink','downlink','none') NOT NULL default 'none'";
3a387b0d
DO
801 $query[] = "UPDATE Config SET varvalue = '0.18.4' WHERE varname = 'DB_VERSION'";
802 break;
95857b5c 803 case '0.18.5':
1f54e1ba 804 $query = array_merge ($query, reloadDictionary ($batchid));
95857b5c 805 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('SHRINK_TAG_TREE_ON_CLICK','yes','string','no','no','yes','Dynamically hide useless tags in tagtree')";
1f54e1ba 806 $query[] = "ALTER TABLE `IPv4LB` ADD COLUMN `prio` int(10) unsigned DEFAULT NULL AFTER `vs_id`";
1ebbf889 807 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('MAX_UNFILTERED_ENTITIES','0','uint','no','no','yes','Max item count to display on unfiltered result page')";
95857b5c 808 $query[] = "UPDATE Config SET varvalue = '0.18.5' WHERE varname = 'DB_VERSION'";
f2f95f99
JT
809 break;
810 case '0.18.6':
811 $query = array_merge ($query, reloadDictionary ($batchid));
812 $query[] = "UPDATE Config SET varvalue = '0.18.6' WHERE varname = 'DB_VERSION'";
95857b5c 813 break;
9fb6900d
DO
814 case '0.18.7':
815 $query = array_merge ($query, reloadDictionary ($batchid));
816 $query[] = "UPDATE Config SET varvalue = '0.18.7' WHERE varname = 'DB_VERSION'";
817 break;
d3346ce2 818 case '0.19.0':
0682218d 819 $query = array_merge ($query, reloadDictionary ($batchid));
d3346ce2 820 $query[] = 'ALTER TABLE `File` ADD `thumbnail` LONGBLOB NULL AFTER `atime`';
21ee3351
AA
821 $query[] = "
822CREATE TABLE `IPv6Address` (
823 `ip` binary(16) NOT NULL,
824 `name` char(255) NOT NULL default '',
825 `reserved` enum('yes','no') default NULL,
826 PRIMARY KEY (`ip`)
827) ENGINE=InnoDB
828";
829 $query[] = "
830CREATE TABLE `IPv6Allocation` (
831 `object_id` int(10) unsigned NOT NULL default '0',
832 `ip` binary(16) NOT NULL,
833 `name` char(255) NOT NULL default '',
834 `type` enum('regular','shared','virtual','router') default NULL,
8c7b7381
AA
835 PRIMARY KEY (`object_id`,`ip`),
836 CONSTRAINT `IPv6Allocation-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE
21ee3351
AA
837) ENGINE=InnoDB
838";
839 $query[] = "
840CREATE TABLE `IPv6Network` (
841 `id` int(10) unsigned NOT NULL auto_increment,
842 `ip` binary(16) NOT NULL,
843 `mask` int(10) unsigned NOT NULL,
844 `last_ip` binary(16) NOT NULL,
845 `name` char(255) default NULL,
846 `comment` text,
847 PRIMARY KEY (`id`),
848 UNIQUE KEY `ip` (`ip`,`mask`)
849) ENGINE=InnoDB
850";
851 $query[] = "
852CREATE TABLE `VLANIPv6` (
853 `domain_id` int(10) unsigned NOT NULL,
854 `vlan_id` int(10) unsigned NOT NULL,
855 `ipv6net_id` int(10) unsigned NOT NULL,
856 UNIQUE KEY `network-domain` (`ipv6net_id`,`domain_id`),
857 KEY `VLANIPv6-FK-compound` (`domain_id`,`vlan_id`),
858 CONSTRAINT `VLANIPv6-FK-compound` FOREIGN KEY (`domain_id`, `vlan_id`) REFERENCES `VLANDescription` (`domain_id`, `vlan_id`) ON DELETE CASCADE,
859 CONSTRAINT `VLANIPv6-FK-ipv6net_id` FOREIGN KEY (`ipv6net_id`) REFERENCES `IPv6Network` (`id`) ON DELETE CASCADE
860) ENGINE=InnoDB
9a90adc4
DO
861";
862 $query[] = "
8489d2af
DO
863CREATE TABLE IF NOT EXISTS `ObjectLog` (
864 `id` int(10) NOT NULL AUTO_INCREMENT,
865 `object_id` int(10) NOT NULL,
866 `user` varchar(64) NOT NULL,
9a90adc4
DO
867 `date` datetime NOT NULL,
868 `content` text NOT NULL,
8489d2af 869 PRIMARY KEY (`id`)
9a90adc4 870) ENGINE=InnoDB
0682218d 871";
8489d2af
DO
872 # Now we have the same structure of ObjectLog table, which objectlog.php
873 # could have left. Subsequent column updates will handle any existing data.
874 $query[] = "ALTER TABLE ObjectLog MODIFY COLUMN `id` int(10) unsigned NOT NULL AUTO_INCREMENT";
875 $query[] = "ALTER TABLE ObjectLog MODIFY COLUMN `object_id` int(10) unsigned NOT NULL";
876 $query[] = "ALTER TABLE ObjectLog MODIFY COLUMN `user` char(64) NOT NULL";
877 $query[] = "ALTER TABLE ObjectLog ADD KEY `object_id` (`object_id`)";
878 $query[] = "ALTER TABLE ObjectLog ADD KEY `date` (`date`)";
879 $query[] = "ALTER TABLE ObjectLog ADD CONSTRAINT `ObjectLog-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE";
880 # Now it's the way 0.19.0 is expecting it to be.
0682218d
AD
881 $query[] = "
882CREATE TABLE `ObjectParentCompat` (
883 `parent_objtype_id` int(10) unsigned NOT NULL,
884 `child_objtype_id` int(10) unsigned NOT NULL,
885 UNIQUE KEY `parent_child` (`parent_objtype_id`,`child_objtype_id`)
886) ENGINE=InnoDB
887";
888 $query[] = "
889CREATE TABLE `EntityLink` (
890 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
891 `parent_entity_type` enum('ipv4net','ipv4rspool','ipv4vs','ipv6net','object','rack','user') NOT NULL,
892 `parent_entity_id` int(10) unsigned NOT NULL,
893 `child_entity_type` enum('file','object') NOT NULL,
894 `child_entity_id` int(10) unsigned NOT NULL,
895 PRIMARY KEY (`id`),
896 UNIQUE KEY `EntityLink-unique` (`parent_entity_type`,`parent_entity_id`,`child_entity_type`,`child_entity_id`)
897) ENGINE=InnoDB
21ee3351
AA
898";
899 $query[] = "ALTER TABLE `TagStorage` CHANGE COLUMN `entity_realm` `entity_realm` ENUM('file','ipv4net','ipv4vs','ipv4rspool','object','rack','user','ipv6net') NOT NULL DEFAULT 'object' FIRST";
900 $query[] = "ALTER TABLE `FileLink` CHANGE COLUMN `entity_type` `entity_type` ENUM('ipv4net','ipv4rspool','ipv4vs','object','rack','user','ipv6net') NOT NULL DEFAULT 'object' AFTER `file_id`";
0c7c9f8b 901 $query[] = 'ALTER TABLE Link ADD COLUMN cable char(64) NULL AFTER portb';
3fb61857 902 $query[] = 'ALTER TABLE RackSpace ADD CONSTRAINT `RackSpace-FK-rack_id` FOREIGN KEY (rack_id) REFERENCES Rack (id)';
8c7b7381 903 $query[] = "ALTER TABLE `IPv4Allocation` ADD CONSTRAINT `IPv4Allocation-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE";
61e79d63 904 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('SYNCDOMAIN_MAX_PROCESSES','0','uint','yes','no', 'How many worker proceses syncdomain cron script should create')";
fbeacc34 905 $query[] = "ALTER TABLE `VLANSwitchTemplate` ADD COLUMN `mutex_rev` int(10) NOT NULL AFTER `id`";
09ec2e59 906 $query[] = "ALTER TABLE `VLANSwitchTemplate` ADD COLUMN `saved_by` char(64) NOT NULL AFTER `description`";
0682218d
AD
907 $query[] = "INSERT INTO `Attribute` (`id`, `type`, `name`) VALUES (26,'dict','Hypervisor')";
908 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (29,'no','Yes/No')";
909 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (30,'no','network chassis models')";
910 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (31,'no','server chassis models')";
911 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (32,'no','virtual switch models')";
912 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (33,'no','virtual switch OS type')";
913 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (4,26,29)";
914 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1502,1,NULL)";
915 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1502,2,31)";
916 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1502,3,NULL)";
917 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1502,14,NULL)";
918 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1502,20,NULL)";
919 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1502,21,NULL)";
920 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1502,22,NULL)";
921 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,1,NULL)";
922 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,2,30)";
923 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,3,NULL)";
588c98f8
AD
924 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,4,14)";
925 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,5,NULL)";
0682218d 926 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,14,NULL)";
588c98f8
AD
927 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,16,NULL)";
928 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,17,NULL)";
929 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,18,NULL)";
0682218d
AD
930 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,20,NULL)";
931 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,21,NULL)";
932 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,22,NULL)";
588c98f8 933 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,24,NULL)";
0682218d
AD
934 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1504,3,NULL)";
935 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1504,4,13)";
936 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1504,14,NULL)";
937 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1504,24,NULL)";
938 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1505,14,NULL)";
939 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1506,14,NULL)";
940 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1506,17,NULL)";
941 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1506,18,NULL)";
942 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,1,NULL)";
943 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,2,32)";
944 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,3,NULL)";
945 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,4,33)";
946 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,5,NULL)";
947 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,14,NULL)";
948 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,20,NULL)";
949 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,21,NULL)";
950 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,22,NULL)";
951 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (3,13)";
952 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (4,1504)";
953 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (4,1507)";
954 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1502,4)";
955 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1503,8)";
956 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1505,4)";
957 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1505,1504)";
958 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1505,1506)";
959 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1505,1507)";
960 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1506,1504)";
0682218d 961 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('PORT_EXCLUSION_LISTSRC','{\$typeid_3} or {\$typeid_10} or {\$typeid_11} or {\$typeid_1505} or {\$typeid_1506}','string','yes','no','no','List source: objects without ports')";
322ce490 962 $query[] = "UPDATE Config SET varvalue = CONCAT(varvalue, ' or {\$typeid_1502} or {\$typeid_1503} or {\$typeid_1504} or {\$typeid_1507}') WHERE varname = 'IPV4OBJ_LISTSRC'";
0682218d 963 $query[] = "UPDATE Config SET varvalue = '8' WHERE varname = 'MASSCOUNT'";
993f5fa3 964 $query[] = "UPDATE RackObject SET label = NULL WHERE label = ''";
81659c05
AD
965 // Move barcode data so the column can be dropped
966 $result = $dbxlink->query ('SELECT id, objtype_id, barcode FROM RackObject WHERE barcode IS NOT NULL');
a7978f7f
AD
967 $rows = $result->fetchAll (PDO::FETCH_ASSOC);
968 unset ($result);
969 foreach ($rows as $row)
81659c05
AD
970 {
971 // Determine if this object type has the 'OEM S/N 1' attribute associated with it, and if it's set
972 $sn_query = "SELECT (SELECT COUNT(*) FROM AttributeMap WHERE objtype_id=${row['objtype_id']} AND attr_id=1) AS AM_count, ";
973 $sn_query .= "(SELECT COUNT(*) FROM AttributeValue WHERE object_id=${row['id']} AND attr_id=1) AS AV_count";
974 $sn_result = $dbxlink->query ($sn_query);
975 $sn_row = $sn_result->fetch (PDO::FETCH_ASSOC);
976 if ($sn_row['AM_count'] == 1 && $sn_row['AV_count'] == 0)
977 {
978 // 'OEM S/N 1' attribute is mapped to this object type, but it is not set. Good!
979 // Copy the barcode value to the attribute.
980 $query[] = "INSERT INTO AttributeValue (`object_id`, `attr_id`, `string_value`) VALUES (${row['id']}, 1, '${row['barcode']}')";
981 }
982 else
983 {
984 // Some other set of circumstances. Not as good!
985 // Copy the barcode value to a new ObjectLog record.
986 $query[] = "INSERT INTO ObjectLog (`object_id`, `user`, `date`, `content`) VALUES (${row['id']}, '${_SERVER['PHP_AUTH_USER']}', NOW(), 'Upgrade to 0.19 dropped the barcode column. Value was: ${row['barcode']}')";
987 }
988 unset ($sn_query, $sn_result, $sn_row);
989 }
81659c05
AD
990 $query[] = 'ALTER TABLE RackObject DROP COLUMN `barcode`';
991 $query[] = 'ALTER TABLE RackObjectHistory DROP COLUMN `barcode`';
fbeacc34 992 $query[] = 'ALTER TABLE `VLANSwitchTemplate` DROP COLUMN `max_local_vlans`';
81659c05 993 $query[] = "UPDATE Config SET varvalue = '0.19.0' WHERE varname = 'DB_VERSION'";
d3346ce2 994 break;
6d42599c
AA
995 case '0.19.1':
996 $query = array_merge ($query, reloadDictionary ($batchid));
1d5dd3a1
AD
997 $query[] = "ALTER TABLE `Config` CHANGE COLUMN `varvalue` `varvalue` text NOT NULL";
998 $query[] = "ALTER TABLE `UserConfig` CHANGE COLUMN `varvalue` `varvalue` text NOT NULL";
6d42599c 999 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('FILTER_RACKLIST_BY_TAGS','yes','string','yes','no','yes','Rackspace: show only racks matching the current object\'s tags')";
782ad4cd
DO
1000 $result = $dbxlink->query ("SHOW TABLES LIKE 'Objectlog'");
1001 $rows = $result->fetchAll (PDO::FETCH_ASSOC);
1002 unset ($result);
1003 if (count ($rows))
1004 {
1005 # Now the ObjectLog merge... again, because the original table is named
1006 # "Objectlog". The job is to merge contents of Objectlog and ObjectLog
1007 # into the latter.
1008 $query[] = "INSERT INTO ObjectLog (object_id, user, date, content) SELECT object_id, user, date, content FROM Objectlog WHERE object_id IN(SELECT id FROM RackObject)";
1009 $query[] = "DELETE FROM Objectlog WHERE object_id IN(SELECT id FROM RackObject)";
1010 # Don't delete the old table, if the merge wasn't exhaustive.
1011 $result = $dbxlink->query ('SELECT COUNT(*) AS c FROM Objectlog WHERE object_id NOT IN(SELECT id FROM RackObject)');
1012 $row = $result->fetch (PDO::FETCH_ASSOC);
1013 unset ($result);
1014 if ($row['c'] == 0)
1015 $query[] = 'DROP TABLE Objectlog';
1016 else
1017 $query[] = 'ALTER TABLE Objectlog RENAME TO Objectlog_old_unmerged';
1018 }
6d42599c
AA
1019 $query[] = "UPDATE Config SET varvalue = '0.19.1' WHERE varname = 'DB_VERSION'";
1020 break;
f701420b
AA
1021 case '0.19.2':
1022 $query = array_merge ($query, reloadDictionary ($batchid));
1023 $query[] = "ALTER TABLE IPv4Allocation ADD KEY `ip` (`ip`)";
1024 $query[] = "ALTER TABLE IPv6Allocation ADD KEY `ip` (`ip`)";
1025 $query[] = "ALTER TABLE IPv4VS ADD KEY `vip` (`vip`)";
1026 $query[] = "ALTER TABLE IPv4RS ADD KEY `rsip` (`rsip`)";
ae67fa11
AD
1027 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (34,'no','power supply chassis models')";
1028 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (35,'no','power supply models')";
1029 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1397,1,NULL)";
1030 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1397,2,34)";
1031 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1397,14,NULL)";
1032 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1397,21,NULL)";
1033 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1397,22,NULL)";
1034 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1398,1,NULL)";
1035 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1398,2,35)";
1036 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1398,14,NULL)";
1037 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1398,21,NULL)";
1038 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1398,22,NULL)";
1039 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1397,1398)";
1040 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (1399,1399)";
1041 $query[] = "INSERT INTO `PortInterfaceCompat` (`iif_id`, `oif_id`) VALUES (1,1399)";
1042 $query[] = "UPDATE Config SET varvalue = CONCAT(varvalue, ' or {\$typeid_1397}') WHERE varname = 'IPV4OBJ_LISTSRC'";
c4ad9ac0
AA
1043 $query[] = "ALTER TABLE AttributeValue ADD KEY `attr_id-uint_value` (`attr_id`,`uint_value`)";
1044 $query[] = "ALTER TABLE AttributeValue ADD KEY `attr_id-string_value` (`attr_id`,`string_value`(12))";
0abae5fb 1045 $query[] = "UPDATE Config SET varvalue = '0.19.2' WHERE varname = 'DB_VERSION'";
f701420b 1046 break;
6d2cc13e
DO
1047 case '0.19.3':
1048 $query = array_merge ($query, reloadDictionary ($batchid));
1049 $query[] = "DELETE FROM RackSpace WHERE object_id IS NULL AND state = 'T'";
1050 $query[] = "UPDATE Config SET varvalue = '0.19.3' WHERE varname = 'DB_VERSION'";
1051 break;
85e868a0
AA
1052 case '0.20.0':
1053 $query = array_merge ($query, reloadDictionary ($batchid));
5c6225b1
AA
1054 $query[] = "
1055CREATE TABLE `PortLog` (
1056 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
1057 `port_id` int(10) unsigned NOT NULL,
5c6225b1 1058 `date` datetime NOT NULL,
68c91b9c
AA
1059 `user` varchar(64) NOT NULL,
1060 `message` text NOT NULL,
5c6225b1
AA
1061 PRIMARY KEY (`id`),
1062 KEY `port_id-date` (`port_id`,`date`),
1063 CONSTRAINT `PortLog_ibfk_1` FOREIGN KEY (`port_id`) REFERENCES `Port` (`id`) ON DELETE CASCADE
1064) ENGINE=InnoDB;
68c91b9c
AA
1065";
1066 $query[] = "
1067CREATE TABLE `IPv4Log` (
1068 `id` int(10) NOT NULL AUTO_INCREMENT,
1069 `ip` int(10) unsigned NOT NULL,
1070 `date` datetime NOT NULL,
1071 `user` varchar(64) NOT NULL,
1072 `message` text NOT NULL,
1073 PRIMARY KEY (`id`),
1074 KEY `ip-date` (`ip`,`date`)
1075) ENGINE=InnoDB;
5c6225b1 1076";
52d31972
DO
1077 for ($i = 1424; $i <= 1466; $i++) # CX, then 42 ER channels
1078 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (${i},${i})";
8920f7f5
DO
1079 # Dismiss some overly-specific OIF types in favour of more generic counterparts.
1080 $squeeze = array
1081 (
1082 1202 => array # 1000Base-SX
1083 (
1084 25, # 1000Base-SX (SC)
1085 26, # 1000Base-SX (LC)
1086 ),
1087 1204 => array # 1000Base-LX
1088 (
1089 27, # 1000Base-LX (SC)
1090 28, # 1000Base-LX (LC)
1091 ),
1092 1196 => array # 100Base-SX
1093 (
1094 22, # 100Base-SX (SC)
1095 23, # 100Base-SX (LC)
1096 ),
1097 1195 => array # 100Base-FX
1098 (
1099 20, # 100Base-FX (SC)
1100 21, # 100Base-FX (LC)
1101 1083, # 100Base-FX (MT-RJ)
1102 ),
1103 );
1104 foreach ($squeeze as $stays => $leaves)
1105 {
1106 $csv = implode (', ', $leaves);
1107 $query[] = "DELETE FROM PortCompat WHERE type1 IN(${csv}) OR type2 IN(${csv})";
1108 $query[] = "INSERT IGNORE INTO PortInterfaceCompat (iif_id, oif_id) SELECT iif_id, ${stays} FROM Port WHERE type IN (${csv})";
1109 $query[] = "UPDATE Port SET type = ${stays} WHERE type IN(${csv})";
1110 $query[] = "DELETE FROM PortInterfaceCompat WHERE oif_id IN(${csv})";
1111 }
852c508a
AA
1112 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('SSH_OBJS_LISTSRC','none','string','yes','no','yes','Rackcode filter for SSH-managed objects')";
1113 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('TELNET_OBJS_LISTSRC','none','string','yes','no','yes','Rackcode filter for telnet-managed objects')";
2f2bcbfc 1114 $query[] = "DELETE FROM Config WHERE varname = 'HNDP_RUNNERS_LISTSRC'";
cc3d6915 1115 $query[] = "ALTER TABLE TagStorage MODIFY COLUMN entity_realm ENUM('file','ipv4net','ipv4vs','ipv4rspool','object','rack','user','ipv6net','vst') NOT NULL default 'object'";
30bb83bd 1116 $query[] = "ALTER TABLE `TagStorage` ADD COLUMN `user` char(64) DEFAULT NULL, ADD COLUMN `date` datetime DEFAULT NULL";
85e868a0
AA
1117 $query[] = "UPDATE Config SET varvalue = '0.20.0' WHERE varname = 'DB_VERSION'";
1118 break;
fbbb74fb 1119 default:
964b0388 1120 showError ("executeUpgradeBatch () failed, because batch '${batchid}' isn't defined", __FUNCTION__);
fbbb74fb
DO
1121 die;
1122 break;
1123 }
fbbb74fb 1124 $failures = array();
4114697d 1125 echo "<tr><th>Executing batch '${batchid}'</th><td>";
fbbb74fb
DO
1126 foreach ($query as $q)
1127 {
babe4bf5
AA
1128 try
1129 {
1130 $result = $dbxlink->query ($q);
1131 }
1132 catch (PDOException $e)
758fe24c 1133 {
758fe24c
DO
1134 $errorInfo = $dbxlink->errorInfo();
1135 $failures[] = array ($q, $errorInfo[2]);
1136 }
fbbb74fb 1137 }
fbbb74fb 1138 if (!count ($failures))
4114697d 1139 echo "<strong><font color=green>done</font></strong>";
fbbb74fb
DO
1140 else
1141 {
4114697d 1142 echo "<strong><font color=red>The following queries failed:</font></strong><br><pre>";
fbbb74fb
DO
1143 foreach ($failures as $f)
1144 {
1145 list ($q, $i) = $f;
4114697d 1146 echo "${q} -- ${i}\n";
fbbb74fb 1147 }
4114697d 1148 echo "</pre>";
fbbb74fb 1149 }
4114697d 1150 echo '</td></tr>';
fbbb74fb
DO
1151}
1152
120e9ddd 1153function authenticate_admin ($username, $password)
a1f3710a 1154{
43c7895d 1155 global $dbxlink;
4dd08c61
DO
1156 $prepared = $dbxlink->prepare ('SELECT COUNT(*) FROM UserAccount WHERE user_id=1 AND user_name=? AND user_password_hash=?');
1157 if (!$prepared->execute (array ($username, sha1 ($password))))
a1f3710a 1158 die ('SQL query failed in ' . __FUNCTION__);
4dd08c61 1159 $rows = $prepared->fetchAll (PDO::FETCH_NUM);
43c7895d 1160 return $rows[0][0] == 1;
a1f3710a
DO
1161}
1162
c4ee2310
DO
1163// Database version detector. Should behave corretly on any
1164// working dataset a user might have.
1165function getDatabaseVersion ()
1166{
2f5e4db9
DO
1167 global $dbxlink;
1168 $prepared = $dbxlink->prepare ('SELECT varvalue FROM Config WHERE varname = "DB_VERSION" and vartype = "string"');
1169 if (! $prepared->execute())
c4ee2310 1170 {
c4ee2310 1171 $errorInfo = $dbxlink->errorInfo();
2f5e4db9 1172 die (__FUNCTION__ . ': SQL query failed with error ' . $errorInfo[2]);
c4ee2310 1173 }
2f5e4db9 1174 $rows = $prepared->fetchAll (PDO::FETCH_NUM);
c4ee2310
DO
1175 unset ($result);
1176 if (count ($rows) != 1 || !strlen ($rows[0][0]))
1177 die (__FUNCTION__ . ': Cannot guess database version. Config table is present, but DB_VERSION is missing or invalid. Giving up.');
1178 $ret = $rows[0][0];
1179 return $ret;
1180}
1181
964b0388 1182function showError ($info = '', $location = 'N/A')
c4ee2310
DO
1183{
1184 if (preg_match ('/\.php$/', $location))
1185 $location = basename ($location);
1186 elseif ($location != 'N/A')
1187 $location = $location . '()';
1188 echo "<div class=msg_error>An error has occured in [${location}]. ";
1189 if (!strlen ($info))
1190 echo 'No additional information is available.';
1191 else
1192 echo "Additional information:<br><p>\n<pre>\n${info}\n</pre></p>";
2f5e4db9 1193 echo "Go back or try starting from <a href='index.php'>index page</a>.<br></div>\n";
c4ee2310
DO
1194}
1195
964b0388 1196function renderUpgraderHTML()
99ee5479 1197{
b00cc78c
AA
1198 global $found_secret_file;
1199 if (! $found_secret_file)
1200 die ('<center>There is no working RackTables instance here, <a href="?module=installer">install</a>?</center>');
1201
1202 try
964b0388 1203 {
b00cc78c
AA
1204 connectDB();
1205 }
1206 catch (RackTablesError $e)
1207 {
1208 die ("Database connection failed:\n\n" . $e->getMessage());
1209 }
1210
1211 if
1212 (
1213 !isset ($_SERVER['PHP_AUTH_USER']) or
1214 !strlen ($_SERVER['PHP_AUTH_USER']) or
1215 !isset ($_SERVER['PHP_AUTH_PW']) or
1216 !strlen ($_SERVER['PHP_AUTH_PW']) or
1217 !authenticate_admin ($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])
1218 )
1219 {
1220 header ('WWW-Authenticate: Basic realm="RackTables upgrade"');
1221 header ('HTTP/1.0 401 Unauthorized');
1222 showError ('You must be authenticated as an administrator to complete the upgrade.', __FUNCTION__);
120e9ddd 1223 die;
964b0388 1224 }
fbbb74fb 1225
964b0388 1226?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5f016d39 1227<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
2cf36003 1228<head><title>RackTables upgrade script</title>
964b0388
DO
1229<style type="text/css">
1230.tdleft {
1231 text-align: left;
1232}
1233
1234.trok {
1235 background-color: #80FF80;
1236}
1237
1238.trwarning {
1239 background-color: #FFFF80;
1240}
1241
1242.trerror {
1243 background-color: #FF8080;
1244}
1245</style>
5f016d39
DO
1246</head>
1247<body>
1248<h1>Platform check status</h1>
1249<?php
1250
1251if (!platform_is_ok())
1252 die ('</body></html>');
1253
1254echo '<h1>Upgrade status</h1>';
fbbb74fb 1255$dbver = getDatabaseVersion();
5f016d39 1256echo '<table border=1 cellpadding=5>';
4114697d
DO
1257echo "<tr><th>Current status</th><td>Data version: ${dbver}<br>Code version: " . CODE_VERSION . "</td></tr>\n";
1258
1259$path = getDBUpgradePath ($dbver, CODE_VERSION);
1260if ($path === NULL)
758fe24c 1261{
4114697d 1262 echo "<tr><th>Upgrade path</th><td><font color=red>not found</font></td></tr>\n";
d74ae24c
DO
1263 echo "<tr><th>Summary</th><td>Check README for more information. RackTables releases prior to 0.16.4 ";
1264 echo "must be upgraded to 0.16.4 first.</td></tr>\n";
758fe24c 1265}
4114697d 1266else
5f4027b8 1267{
4114697d
DO
1268 if (!count ($path))
1269 echo "<tr><th>Summary</th><td>Come back later.</td></tr>\n";
1270 else
1271 {
1272 echo "<tr><th>Upgrade path</th><td>${dbver} &rarr; " . implode (' &rarr; ', $path) . "</td></tr>\n";
1273 foreach ($path as $batchid)
1274 {
1275 executeUpgradeBatch ($batchid);
1276 if (isset ($relnotes[$batchid]))
5ae6d365 1277 echo "<tr><th>Release notes for ${batchid}</th><td><pre>" . $relnotes[$batchid] . "</pre></td></tr>\n";
4114697d 1278 }
790a60e8 1279 echo "<tr><th>Summary</th><td>Upgrade complete, it is Ok to <a href='index.php'>enter</a> the system.</td></tr>\n";
4114697d 1280 }
5f4027b8 1281}
4114697d 1282echo '</table>';
5f016d39 1283echo '</body></html>';
964b0388 1284}
fbbb74fb
DO
1285
1286?>