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