More Fixes
[public/netxms.git] / src / server / tools / nxdbmgr / upgrade.cpp
CommitLineData
6f33021d 1/*
5039dede 2** nxdbmgr - NetXMS database manager
035745fc 3** Copyright (C) 2004-2014 Victor Kirhenshtein
5039dede
AK
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
19** File: upgrade.cpp
20**
21**/
22
23#include "nxdbmgr.h"
24
4f50e45c
VK
25/**
26 * Externals
27 */
7a41a06e
VK
28BOOL MigrateMaps();
29
4f50e45c
VK
30/**
31 * Create table
32 */
5039dede
AK
33static BOOL CreateTable(const TCHAR *pszQuery)
34{
5039dede 35 BOOL bResult;
7618e362 36 String query(pszQuery);
5039dede 37
6bcafa2d
VK
38 query.replace(_T("$SQL:TEXT"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]);
39 query.replace(_T("$SQL:TXT4K"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT4K]);
40 query.replace(_T("$SQL:INT64"), g_pszSqlType[g_iSyntax][SQL_TYPE_INT64]);
5039dede 41 if (g_iSyntax == DB_SYNTAX_MYSQL)
7618e362
VK
42 query += g_pszTableSuffix;
43 bResult = SQLQuery(query);
5039dede
AK
44 return bResult;
45}
46
4f50e45c
VK
47/**
48 * Create configuration parameter if it doesn't exist (unless bForceUpdate set to true)
49 */
b3eb058b 50BOOL CreateConfigParam(const TCHAR *pszName, const TCHAR *pszValue, int iVisible, int iNeedRestart, BOOL bForceUpdate)
5039dede 51{
42475f3e 52 TCHAR szQuery[1024];
5039dede
AK
53 DB_RESULT hResult;
54 BOOL bVarExist = FALSE, bResult = TRUE;
55
56 // Check for variable existence
08b214c6 57 _sntprintf(szQuery, 1024, _T("SELECT var_value FROM config WHERE var_name='%s'"), pszName);
5039dede
AK
58 hResult = DBSelect(g_hCoreDB, szQuery);
59 if (hResult != 0)
60 {
61 if (DBGetNumRows(hResult) > 0)
62 bVarExist = TRUE;
63 DBFreeResult(hResult);
64 }
65
66 if (!bVarExist)
67 {
08b214c6 68 _sntprintf(szQuery, 1024, _T("INSERT INTO config (var_name,var_value,is_visible,")
6f33021d 69 _T("need_server_restart) VALUES (%s,%s,%d,%d)"),
70 (const TCHAR *)DBPrepareString(g_hCoreDB, pszName, 63),
42475f3e 71 (const TCHAR *)DBPrepareString(g_hCoreDB, pszValue, 255), iVisible, iNeedRestart);
5039dede
AK
72 bResult = SQLQuery(szQuery);
73 }
74 else if (bForceUpdate)
75 {
42475f3e
VK
76 _sntprintf(szQuery, 1024, _T("UPDATE config SET var_value=%s WHERE var_name=%s"),
77 (const TCHAR *)DBPrepareString(g_hCoreDB, pszValue, 255), (const TCHAR *)DBPrepareString(g_hCoreDB, pszName, 63));
5039dede
AK
78 bResult = SQLQuery(szQuery);
79 }
80 return bResult;
81}
82
4f50e45c
VK
83/**
84 * Set primary key constraint
85 */
5039dede
AK
86static BOOL SetPrimaryKey(const TCHAR *table, const TCHAR *key)
87{
88 TCHAR query[4096];
89
90 if (g_iSyntax == DB_SYNTAX_SQLITE)
91 return TRUE; // SQLite does not support adding constraints
6f33021d 92
5039dede
AK
93 _sntprintf(query, 4096, _T("ALTER TABLE %s ADD PRIMARY KEY (%s)"), table, key);
94 return SQLQuery(query);
95}
96
4f50e45c
VK
97/**
98 * Drop primary key from table
99 */
9bfc9a6b
VK
100static BOOL DropPrimaryKey(const TCHAR *table)
101{
102 TCHAR query[1024];
103 DB_RESULT hResult;
104 BOOL success;
105
106 switch(g_iSyntax)
107 {
108 case DB_SYNTAX_ORACLE:
109 case DB_SYNTAX_MYSQL:
110 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP PRIMARY KEY"), table);
111 success = SQLQuery(query);
112 break;
113 case DB_SYNTAX_PGSQL:
114 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP CONSTRAINT %s_pkey"), table, table);
115 success = SQLQuery(query);
116 break;
117 case DB_SYNTAX_MSSQL:
118 success = FALSE;
119 _sntprintf(query, 1024, _T("SELECT name FROM sysobjects WHERE xtype='PK' AND parent_obj=OBJECT_ID('%s')"), table);
120 hResult = SQLSelect(query);
121 if (hResult != NULL)
122 {
123 if (DBGetNumRows(hResult) > 0)
124 {
125 TCHAR objName[512];
126
127 DBGetField(hResult, 0, 0, objName, 512);
128 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP CONSTRAINT %s"), table, objName);
129 success = SQLQuery(query);
130 }
131 DBFreeResult(hResult);
132 }
133 break;
134 default: // Unsupported DB engine
135 success = FALSE;
136 break;
137 }
138 return success;
139}
140
4f50e45c
VK
141/**
142 * Convert strings from # encoded form to normal form
143 */
d6bf58f9 144static BOOL ConvertStrings(const TCHAR *table, const TCHAR *idColumn, const TCHAR *idColumn2, const TCHAR *column, bool isStringId)
643c9dcb
VK
145{
146 DB_RESULT hResult;
147 TCHAR *query;
148 int queryLen = 512;
149 BOOL success = FALSE;
150
c29fb885 151 query = (TCHAR *)malloc(queryLen * sizeof(TCHAR));
fe12a1ea 152
a4743a0f
VK
153 switch(g_iSyntax)
154 {
155 case DB_SYNTAX_MSSQL:
9f6712bc 156 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE CAST(%s AS nvarchar(4000))=N'#00'"), table, column, column);
a4743a0f
VK
157 break;
158 case DB_SYNTAX_ORACLE:
159 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE to_char(%s)='#00'"), table, column, column);
160 break;
161 default:
162 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE %s='#00'"), table, column, column);
163 break;
164 }
fe12a1ea
VK
165 if (!SQLQuery(query))
166 {
167 free(query);
168 return FALSE;
169 }
170
6f33021d 171 _sntprintf(query, queryLen, _T("SELECT %s,%s%s%s FROM %s WHERE %s LIKE '%%#%%'"),
98cd01bb 172 idColumn, column, (idColumn2 != NULL) ? _T(",") : _T(""), (idColumn2 != NULL) ? idColumn2 : _T(""), table, column);
643c9dcb
VK
173 hResult = SQLSelect(query);
174 if (hResult == NULL)
175 {
176 free(query);
177 return FALSE;
178 }
179
180 int count = DBGetNumRows(hResult);
181 for(int i = 0; i < count; i++)
182 {
643c9dcb 183 TCHAR *value = DBGetField(hResult, i, 1, NULL, 0);
035a4d73 184 if (_tcschr(value, _T('#')) != NULL)
643c9dcb 185 {
035a4d73
VK
186 DecodeSQLString(value);
187 String newValue = DBPrepareString(g_hCoreDB, value);
188 if ((int)newValue.getSize() + 256 > queryLen)
189 {
190 queryLen = newValue.getSize() + 256;
c29fb885 191 query = (TCHAR *)realloc(query, queryLen * sizeof(TCHAR));
035a4d73 192 }
d6bf58f9 193 if (isStringId)
98cd01bb 194 {
d6bf58f9
VK
195 TCHAR *id = DBGetField(hResult, i, 0, NULL, 0);
196 if (idColumn2 != NULL)
197 {
198 TCHAR *id2 = DBGetField(hResult, i, 2, NULL, 0);
199 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=%s AND %s=%s"),
200 table, column, (const TCHAR *)newValue,
6f33021d 201 idColumn, (const TCHAR *)DBPrepareString(g_hCoreDB, id),
d6bf58f9
VK
202 idColumn2, (const TCHAR *)DBPrepareString(g_hCoreDB, id2));
203 }
204 else
205 {
206 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=%s"), table, column,
207 (const TCHAR *)newValue, idColumn, (const TCHAR *)DBPrepareString(g_hCoreDB, id));
208 }
209 free(id);
98cd01bb
VK
210 }
211 else
212 {
d6bf58f9
VK
213 INT64 id = DBGetFieldInt64(hResult, i, 0);
214 if (idColumn2 != NULL)
215 {
216 INT64 id2 = DBGetFieldInt64(hResult, i, 2);
6f33021d 217 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=") INT64_FMT _T(" AND %s=") INT64_FMT,
d6bf58f9
VK
218 table, column, (const TCHAR *)newValue, idColumn, id, idColumn2, id2);
219 }
220 else
221 {
222 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=") INT64_FMT, table, column,
223 (const TCHAR *)newValue, idColumn, id);
224 }
98cd01bb 225 }
035a4d73
VK
226 if (!SQLQuery(query))
227 goto cleanup;
643c9dcb 228 }
643c9dcb
VK
229 }
230 success = TRUE;
231
232cleanup:
233 DBFreeResult(hResult);
a4743a0f 234 free(query);
643c9dcb
VK
235 return success;
236}
237
98cd01bb
VK
238static BOOL ConvertStrings(const TCHAR *table, const TCHAR *idColumn, const TCHAR *column)
239{
d6bf58f9 240 return ConvertStrings(table, idColumn, NULL, column, false);
98cd01bb
VK
241}
242
4f50e45c 243/**
70ffb771 244 * Set column nullable (currently only Oracle and PostgreSQL)
4f50e45c 245 */
480e036b 246static BOOL SetColumnNullable(const TCHAR *table, const TCHAR *column)
1024e962
VK
247{
248 TCHAR query[1024] = _T("");
249
250 switch(g_iSyntax)
251 {
252 case DB_SYNTAX_ORACLE:
253 _sntprintf(query, 1024, _T("DECLARE already_null EXCEPTION; ")
254 _T("PRAGMA EXCEPTION_INIT(already_null, -1451); ")
f57209fd
VK
255 _T("BEGIN EXECUTE IMMEDIATE 'ALTER TABLE %s MODIFY %s null'; ")
256 _T("EXCEPTION WHEN already_null THEN null; END;"), table, column);
1024e962 257 break;
480e036b
VK
258 case DB_SYNTAX_PGSQL:
259 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s DROP NOT NULL"), table, column);
260 break;
1024e962
VK
261 default:
262 break;
263 }
264
265 return (query[0] != 0) ? SQLQuery(query) : TRUE;
266}
267
480e036b
VK
268/**
269 * Resize varchar column
270 */
271static BOOL ResizeColumn(const TCHAR *table, const TCHAR *column, int newSize)
272{
273 TCHAR query[1024];
274
275 switch(g_iSyntax)
276 {
277 case DB_SYNTAX_DB2:
278 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s SET DATA TYPE varchar(%d)"), table, column, newSize);
279 break;
280 case DB_SYNTAX_MSSQL:
281 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s varchar(%d)"), table, column, newSize);
282 break;
283 case DB_SYNTAX_PGSQL:
284 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s TYPE varchar(%d)"), table, column, newSize);
285 break;
286 case DB_SYNTAX_SQLITE:
287 /* TODO: add SQLite support */
288 query[0] = 0;
289 break;
290 default:
291 _sntprintf(query, 1024, _T("ALTER TABLE %s MODIFY %s varchar(%d)"), table, column, newSize);
292 break;
293 }
294
295 return (query[0] != 0) ? SQLQuery(query) : TRUE;
296}
297
4f50e45c
VK
298/**
299 * Create new event template
300 */
aa16f82b
VK
301static BOOL CreateEventTemplate(int code, const TCHAR *name, int severity, int flags, const TCHAR *message, const TCHAR *description)
302{
480e036b 303 TCHAR query[4096];
aa16f82b 304
480e036b
VK
305 _sntprintf(query, 4096, _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (%d,'%s',%d,%d,%s,%s)"),
306 code, name, severity, flags, (const TCHAR *)DBPrepareString(g_hCoreDB, message),
307 (const TCHAR *)DBPrepareString(g_hCoreDB, description));
aa16f82b
VK
308 return SQLQuery(query);
309}
310
22aaa779
VK
311/**
312 * Re-create TDATA tables
313 */
1d4f7890 314static BOOL RecreateTData(const TCHAR *className, bool multipleTables)
22aaa779 315{
1d4f7890 316 TCHAR query[1024];
22aaa779
VK
317 _sntprintf(query, 256, _T("SELECT id FROM %s"), className);
318 DB_RESULT hResult = SQLSelect(query);
319 if (hResult != NULL)
320 {
321 int count = DBGetNumRows(hResult);
322 for(int i = 0; i < count; i++)
323 {
324 DWORD id = DBGetFieldULong(hResult, i, 0);
325
1d4f7890
VK
326 if (multipleTables)
327 {
328 _sntprintf(query, 1024, _T("DROP TABLE tdata_rows_%d\nDROP TABLE tdata_records_%d\nDROP TABLE tdata_%d\n<END>"), id, id, id);
329 }
330 else
331 {
332 _sntprintf(query, 256, _T("DROP TABLE tdata_%d\n<END>"), id);
333 }
334 if (!SQLBatch(query))
22aaa779
VK
335 {
336 if (!g_bIgnoreErrors)
337 {
338 DBFreeResult(hResult);
339 return FALSE;
340 }
341 }
342
343 if (!CreateTDataTables(id))
344 {
345 if (!g_bIgnoreErrors)
346 {
347 DBFreeResult(hResult);
348 return FALSE;
349 }
350 }
351 }
352 DBFreeResult(hResult);
353 }
354 else
355 {
356 if (!g_bIgnoreErrors)
357 return FALSE;
358 }
359 return TRUE;
360}
361
6498e05a
VK
362/**
363 * Upgrade from V311 to V312
364 */
365static BOOL H_UpgradeFromV311(int currVersion, int newVersion)
366{
367 CHK_EXEC(CreateConfigParam(_T("EnableReportingServer"), _T("0"), 1, 1));
368 CHK_EXEC(CreateConfigParam(_T("ReportingServerHostname"), _T("localhost"), 1, 1));
369 CHK_EXEC(CreateConfigParam(_T("ReportingServerPort"), _T("4710"), 1, 1));
370 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='312' WHERE var_name='SchemaVersion'")));
371 return TRUE;
372}
373
9262b092
VK
374/**
375 * Upgrade from V310 to V311
376 */
377static BOOL H_UpgradeFromV310(int currVersion, int newVersion)
378{
379 IntegerArray<UINT32> deleteList;
380
381 // reports
382 DB_RESULT hResult = SQLSelect(_T("SELECT id FROM reports"));
383 if (hResult != NULL)
384 {
385 int count = DBGetNumRows(hResult);
386 for(int i = 0; i < count; i++)
387 deleteList.add(DBGetFieldULong(hResult, i, 0));
388 DBFreeResult(hResult);
389 }
390
391 // report groups
392 hResult = SQLSelect(_T("SELECT id FROM containers WHERE object_class=25"));
393 if (hResult != NULL)
394 {
395 int count = DBGetNumRows(hResult);
396 for(int i = 0; i < count; i++)
397 deleteList.add(DBGetFieldULong(hResult, i, 0));
398 DBFreeResult(hResult);
399 }
400
401 for(int i = 0; i < deleteList.size(); i++)
402 {
403 TCHAR query[256];
404
405 _sntprintf(query, 256, _T("DELETE FROM object_properties WHERE object_id=%d"), deleteList.get(i));
406 CHK_EXEC(SQLQuery(query));
407
408 _sntprintf(query, 256, _T("DELETE FROM object_custom_attributes WHERE object_id=%d"), deleteList.get(i));
409 CHK_EXEC(SQLQuery(query));
410
411 _sntprintf(query, 256, _T("DELETE FROM acl WHERE object_id=%d"), deleteList.get(i));
412 CHK_EXEC(SQLQuery(query));
413
414 _sntprintf(query, 256, _T("DELETE FROM container_members WHERE object_id=%d OR container_id=%d"), deleteList.get(i), deleteList.get(i));
415 CHK_EXEC(SQLQuery(query));
416 }
417
418 static TCHAR batch[] =
419 _T("DROP TABLE reports\n")
420 _T("DROP TABLE report_results\n")
421 _T("DELETE FROM containers WHERE object_class=25\n")
422 _T("DELETE FROM object_properties WHERE object_id=8\n")
423 _T("<END>");
424 CHK_EXEC(SQLBatch(batch));
425 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='311' WHERE var_name='SchemaVersion'")));
426 return TRUE;
427}
428
32745683
VK
429/**
430 * Upgrade from V309 to V310
431 */
432static BOOL H_UpgradeFromV309(int currVersion, int newVersion)
433{
434 static TCHAR batch[] =
435 _T("ALTER TABLE interfaces ADD peer_proto integer\n")
436 _T("UPDATE interfaces SET peer_proto=0\n")
437 _T("<END>");
438 CHK_EXEC(SQLBatch(batch));
439 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='310' WHERE var_name='SchemaVersion'")));
440 return TRUE;
441}
442
34a320ad
VK
443/**
444 * Upgrade from V308 to V309
445 */
446static BOOL H_UpgradeFromV308(int currVersion, int newVersion)
447{
448 CHK_EXEC(CreateConfigParam(_T("HelpDeskLink"), _T("none"), 1, 1));
449 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='309' WHERE var_name='SchemaVersion'")));
450 return TRUE;
451}
452
2ab9314f 453/**
454 * Upgrade from V307 to V308
455 */
456static BOOL H_UpgradeFromV307(int currVersion, int newVersion)
457{
458 static TCHAR batch[] =
32745683
VK
459 _T("ALTER TABLE network_map_elements ADD flags integer\n")
460 _T("UPDATE network_map_elements SET flags=0\n") //set all elements like manually generated
461 _T("ALTER TABLE network_map_links ADD element_data $SQL:TEXT\n")
462 _T("ALTER TABLE network_map_links ADD flags integer\n")
463 _T("UPDATE network_map_links SET flags=0\n") //set all elements like manually generated
464 _T("<END>");
2ab9314f 465 CHK_EXEC(SQLBatch(batch));
466
32745683
VK
467 // it is assumed that now all autogenerated maps contain only autogenerated objects and links
468 // get elements from autogenerated maps and set their flags to AUTO_GENERATED for map elements and map links
2ab9314f 469 TCHAR query[256];
470 _sntprintf(query, 256, _T("SELECT id FROM network_maps WHERE map_type=%d OR map_type=%d"),
471 MAP_TYPE_LAYER2_TOPOLOGY, MAP_TYPE_IP_TOPOLOGY);
472 DB_RESULT hResult = SQLSelect(query);
473 if (hResult != NULL)
474 {
475 int count = DBGetNumRows(hResult);
476 for(int i = 0; i < count; i++)
477 {
478 _sntprintf(query, 256, _T("UPDATE network_map_elements SET flags='1' WHERE map_id=%d"),
479 DBGetFieldULong(hResult, i, 0));
480 CHK_EXEC(SQLQuery(query));
481 _sntprintf(query, 256, _T("UPDATE network_map_links SET flags='1' WHERE map_id=%d"),
482 DBGetFieldULong(hResult, i, 0));
483 CHK_EXEC(SQLQuery(query));
484 }
485 DBFreeResult(hResult);
486 }
487
488 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='308' WHERE var_name='SchemaVersion'")));
489 return TRUE;
490}
491
b3eb058b
VK
492/**
493 * Upgrade from V306 to V307
494 */
495static BOOL H_UpgradeFromV306(int currVersion, int newVersion)
496{
497 CHK_EXEC(SetColumnNullable(_T("config_clob"), _T("var_value")));
498 CHK_EXEC(ConvertStrings(_T("config_clob"), _T("var_name"), NULL, _T("var_value"), true));
499 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='307' WHERE var_name='SchemaVersion'")));
500 return TRUE;
501}
502
d1730ccf
VK
503/**
504 * Upgrade from V305 to V306
505 */
506static BOOL H_UpgradeFromV305(int currVersion, int newVersion)
507{
508 CHK_EXEC(CreateConfigParam(_T("ExtendedLogQueryAccessControl"), _T("0"), 1, 0));
509 CHK_EXEC(CreateConfigParam(_T("EnableTimedAlarmAck"), _T("1"), 1, 1));
9a1f7c45 510 CHK_EXEC(CreateConfigParam(_T("EnableCheckPointSNMP"), _T("0"), 1, 0));
d1730ccf
VK
511 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='306' WHERE var_name='SchemaVersion'")));
512 return TRUE;
513}
514
035745fc
VK
515/**
516 * Upgrade from V304 to V305
517 */
518static BOOL H_UpgradeFromV304(int currVersion, int newVersion)
519{
2ab9314f 520 CHK_EXEC(CreateEventTemplate(EVENT_IF_PEER_CHANGED, _T("SYS_IF_PEER_CHANGED"), SEVERITY_NORMAL, EF_LOG,
035745fc
VK
521 _T("New peer for interface %3 is %7 interface %10 (%12)"),
522 _T("Generated when peer information for interface changes.\r\n")
523 _T("Parameters:\r\n")
524 _T(" 1) Local interface object ID\r\n")
525 _T(" 2) Local interface index\r\n")
526 _T(" 3) Local interface name\r\n")
527 _T(" 4) Local interface IP address\r\n")
528 _T(" 5) Local interface MAC address\r\n")
529 _T(" 6) Peer node object ID\r\n")
530 _T(" 7) Peer node name\r\n")
531 _T(" 8) Peer interface object ID\r\n")
532 _T(" 9) Peer interface index\r\n")
533 _T(" 10) Peer interface name\r\n")
534 _T(" 11) Peer interface IP address\r\n")
535 _T(" 12) Peer interface MAC address")));
536 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='305' WHERE var_name='SchemaVersion'")));
537 return TRUE;
538}
539
fce4295c 540/**
541 * Upgrade from V303 to V304
542 */
543static BOOL H_UpgradeFromV303(int currVersion, int newVersion)
544{
d184506f 545 CHK_EXEC(CreateConfigParam(_T("StrictAlarmStatusFlow"), _T("0"), 1, 0));
fce4295c 546 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='304' WHERE var_name='SchemaVersion'")));
547 return TRUE;
548}
549
6f33021d 550/**
551 * Upgrade from V302 to V303
552 */
553static BOOL H_UpgradeFromV302(int currVersion, int newVersion)
554{
555 static TCHAR batch[] =
556 _T("ALTER TABLE alarms ADD ack_timeout integer\n")
557 _T("UPDATE alarms SET ack_timeout='0'\n")
558 _T("<END>");
559 CHK_EXEC(SQLBatch(batch));
560
561 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='303' WHERE var_name='SchemaVersion'")));
562 return TRUE;
563}
564
27088c41
AK
565/**
566 * Upgrade from V301 to V302
567 */
568static BOOL H_UpgradeFromV301(int currVersion, int newVersion)
569{
570 static TCHAR batch[] =
571 _T("DELETE FROM config WHERE var_name='DisableVacuum'\n")
572 _T("<END>");
573 CHK_EXEC(SQLBatch(batch));
574
575 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='302' WHERE var_name='SchemaVersion'")));
576 return TRUE;
577}
578
1d34c533
VK
579/**
580 * Upgrade from V300 to V301
581 */
582static BOOL H_UpgradeFromV300(int currVersion, int newVersion)
583{
584 static TCHAR batch[] =
585 _T("ALTER TABLE thresholds ADD script $SQL:TEXT\n")
586 _T("ALTER TABLE thresholds ADD sample_count integer\n")
587 _T("UPDATE thresholds SET sample_count=parameter_1\n")
588 _T("ALTER TABLE thresholds DROP COLUMN parameter_1\n")
589 _T("ALTER TABLE thresholds DROP COLUMN parameter_2\n")
590 _T("<END>");
591 CHK_EXEC(SQLBatch(batch));
592
593 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='301' WHERE var_name='SchemaVersion'")));
594 return TRUE;
595}
596
244c65ef
VK
597/**
598 * Upgrade from V299 to V300
599 */
600static BOOL H_UpgradeFromV299(int currVersion, int newVersion)
601{
602 CHK_EXEC(CreateConfigParam(_T("EnableXMPPConnector"), _T("0"), 1, 1));
603 CHK_EXEC(CreateConfigParam(_T("XMPPLogin"), _T("netxms@localhost"), 1, 1));
604 CHK_EXEC(CreateConfigParam(_T("XMPPPassword"), _T("netxms"), 1, 1));
605 CHK_EXEC(CreateConfigParam(_T("XMPPServer"), _T("localhost"), 1, 1));
606 CHK_EXEC(CreateConfigParam(_T("XMPPPort"), _T("5222"), 1, 1));
607
608 SetColumnNullable(_T("users"), _T("full_name"));
609 SetColumnNullable(_T("users"), _T("description"));
610 SetColumnNullable(_T("users"), _T("cert_mapping_data"));
611 SetColumnNullable(_T("user_groups"), _T("description"));
612 SetColumnNullable(_T("userdb_custom_attributes"), _T("attr_value"));
613
614 ConvertStrings(_T("users"), _T("id"), _T("full_name"));
615 ConvertStrings(_T("users"), _T("id"), _T("description"));
616 ConvertStrings(_T("users"), _T("id"), _T("cert_mapping_data"));
617 ConvertStrings(_T("user_groups"), _T("id"), _T("description"));
618 ConvertStrings(_T("userdb_custom_attributes"), _T("object_id"), _T("attr_name"), _T("attr_name"), true);
619 ConvertStrings(_T("userdb_custom_attributes"), _T("object_id"), _T("attr_name"), _T("attr_value"), true);
620
621 CHK_EXEC(SQLQuery(_T("ALTER TABLE users ADD xmpp_id varchar(127)")));
622
623 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='300' WHERE var_name='SchemaVersion'")));
624 return TRUE;
625}
626
ce47611c
VK
627/**
628 * Upgrade from V298 to V299
629 */
630static BOOL H_UpgradeFromV298(int currVersion, int newVersion)
631{
632 CHK_EXEC(SQLQuery(_T("UPDATE event_cfg SET message='Subnet %2 added',description='")
633 _T("Generated when subnet object added to the database.\r\n")
634 _T("Parameters:\r\n")
635 _T(" 1) Subnet object ID\r\n")
636 _T(" 2) Subnet name\r\n")
637 _T(" 3) IP address\r\n")
638 _T(" 4) Network mask")
639 _T("' WHERE event_code=2")));
640 CHK_EXEC(SQLQuery(_T("UPDATE event_cfg SET message='Subnet %2 deleted',description='")
641 _T("Generated when subnet object deleted from the database.\r\n")
642 _T("Parameters:\r\n")
643 _T(" 1) Subnet object ID\r\n")
644 _T(" 2) Subnet name\r\n")
645 _T(" 3) IP address\r\n")
646 _T(" 4) Network mask")
647 _T("' WHERE event_code=19")));
648 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='299' WHERE var_name='SchemaVersion'")));
649 return TRUE;
650}
651
af21affe
VK
652/**
653 * Upgrade from V297 to V298
654 */
655static BOOL H_UpgradeFromV297(int currVersion, int newVersion)
656{
657 CHK_EXEC(CreateConfigParam(_T("AgentDefaultSharedSecret"), _T("netxms"), 1, 0));
658 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='298' WHERE var_name='SchemaVersion'")));
659 return TRUE;
660}
661
e02953a4
VK
662/**
663 * Upgrade from V296 to V297
664 */
665static BOOL H_UpgradeFromV296(int currVersion, int newVersion)
666{
667 CHK_EXEC(CreateConfigParam(_T("UseSNMPTrapsForDiscovery"), _T("0"), 1, 1));
668 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='297' WHERE var_name='SchemaVersion'")));
669 return TRUE;
670}
671
71e4ed3a
VK
672/**
673 * Upgrade from V295 to V296
674 */
675static BOOL H_UpgradeFromV295(int currVersion, int newVersion)
676{
677 static TCHAR batch[] =
678 _T("ALTER TABLE nodes ADD boot_time integer\n")
679 _T("UPDATE nodes SET boot_time=0\n")
680 _T("<END>");
681 CHK_EXEC(SQLBatch(batch));
682
683 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='296' WHERE var_name='SchemaVersion'")));
684 return TRUE;
685}
686
c59466d2
VK
687/**
688 * Upgrade from V294 to V295
689 */
690static BOOL H_UpgradeFromV294(int currVersion, int newVersion)
691{
692 CHK_EXEC(CreateConfigParam(_T("IcmpPingTimeout"), _T("1500"), 1, 1));
693 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='295' WHERE var_name='SchemaVersion'")));
694 return TRUE;
695}
696
1d4f7890
VK
697/**
698 * Upgrade from V293 to V294
699 */
700static BOOL H_UpgradeFromV293(int currVersion, int newVersion)
701{
702 static TCHAR batch[] =
703 _T("DELETE FROM metadata WHERE var_name LIKE 'TDataTableCreationCommand_%'\n")
704 _T("INSERT INTO metadata (var_name,var_value)")
705 _T(" VALUES ('TDataTableCreationCommand_0','CREATE TABLE tdata_%d (item_id integer not null,tdata_timestamp integer not null,record_id $SQL:INT64 not null,UNIQUE(record_id))')\n")
706 _T("INSERT INTO metadata (var_name,var_value)")
707 _T(" VALUES ('TDataTableCreationCommand_1','CREATE TABLE tdata_records_%d (record_id $SQL:INT64 not null,row_id $SQL:INT64 not null,instance varchar(255) null,PRIMARY KEY(row_id),FOREIGN KEY (record_id) REFERENCES tdata_%d(record_id) ON DELETE CASCADE)')\n")
708 _T("INSERT INTO metadata (var_name,var_value)")
709 _T(" VALUES ('TDataTableCreationCommand_2','CREATE TABLE tdata_rows_%d (row_id $SQL:INT64 not null,column_id integer not null,value varchar(255) null,PRIMARY KEY(row_id,column_id),FOREIGN KEY (row_id) REFERENCES tdata_records_%d(row_id) ON DELETE CASCADE)')\n")
710 _T("<END>");
711 CHK_EXEC(SQLBatch(batch));
712
713 RecreateTData(_T("nodes"), true);
714 RecreateTData(_T("clusters"), true);
715 RecreateTData(_T("mobile_devices"), true);
716
717 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='294' WHERE var_name='SchemaVersion'")));
718 return TRUE;
719}
720
bc969eaf
VK
721/**
722 * Upgrade from V292 to V293
723 */
724static BOOL H_UpgradeFromV292(int currVersion, int newVersion)
725{
726 CHK_EXEC(CreateConfigParam(_T("DefaultConsoleShortTimeFormat"), _T("HH:mm"), 1, 0));
727 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='293' WHERE var_name='SchemaVersion'")));
728 return TRUE;
729}
730
badf9a95
VK
731/**
732 * Upgrade from V291 to V292
733 */
734static BOOL H_UpgradeFromV291(int currVersion, int newVersion)
735{
736 CHK_EXEC(SQLQuery(_T("ALTER TABLE event_policy ADD rule_guid varchar(36)")));
737
738 // Generate GUIDs for all objects
739 DB_RESULT hResult = SQLSelect(_T("SELECT rule_id FROM event_policy"));
740 if (hResult != NULL)
741 {
742 int count = DBGetNumRows(hResult);
743 for(int i = 0; i < count; i++)
744 {
745 uuid_t guid;
746 TCHAR query[256], buffer[64];
747
748 uuid_generate(guid);
749 _sntprintf(query, 256, _T("UPDATE event_policy SET rule_guid='%s' WHERE rule_id=%d"),
750 uuid_to_string(guid, buffer), DBGetFieldULong(hResult, i, 0));
751 CHK_EXEC(SQLQuery(query));
752 }
753 DBFreeResult(hResult);
754 }
755
756 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='292' WHERE var_name='SchemaVersion'")));
757 return TRUE;
758}
759
48d50116
VK
760/**
761 * Upgrade from V290 to V291
762 */
763static BOOL H_UpgradeFromV290(int currVersion, int newVersion)
764{
765 CHK_EXEC(SQLQuery(_T("UPDATE network_services SET service_type=7 WHERE service_type=6")));
766 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='291' WHERE var_name='SchemaVersion'")));
767 return TRUE;
768}
769
701726bc
VK
770/**
771 * Upgrade from V289 to V290
772 */
773static BOOL H_UpgradeFromV289(int currVersion, int newVersion)
774{
775 CHK_EXEC(SQLQuery(_T("ALTER TABLE network_maps ADD filter $SQL:TEXT")));
776 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='290' WHERE var_name='SchemaVersion'")));
777 return TRUE;
778}
779
90297892
VK
780/**
781 * Upgrade from V288 to V289
782 */
783static BOOL H_UpgradeFromV288(int currVersion, int newVersion)
784{
785 CHK_EXEC(SQLQuery(_T("ALTER TABLE dct_thresholds DROP COLUMN current_state")));
786 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='289' WHERE var_name='SchemaVersion'")));
787 return TRUE;
788}
789
a0dc14f9
VK
790/**
791 * Upgrade from V287 to V288
792 */
793static BOOL H_UpgradeFromV287(int currVersion, int newVersion)
794{
795 CHK_EXEC(CreateEventTemplate(EVENT_TABLE_THRESHOLD_ACTIVATED, _T("SYS_TABLE_THRESHOLD_ACTIVATED"), EVENT_SEVERITY_MINOR, EF_LOG,
796 _T("Threshold activated on table \"%2\" row %4 (%5)"),
797 _T("Generated when table threshold is activated.\r\n")
798 _T("Parameters:\r\n")
799 _T(" 1) Table DCI name\r\n")
800 _T(" 2) Table DCI description\r\n")
801 _T(" 3) Table DCI ID\r\n")
802 _T(" 4) Table row\r\n")
803 _T(" 5) Instance")));
804
805 CHK_EXEC(CreateEventTemplate(EVENT_TABLE_THRESHOLD_DEACTIVATED, _T("SYS_TABLE_THRESHOLD_DEACTIVATED"), EVENT_SEVERITY_NORMAL, EF_LOG,
806 _T("Threshold deactivated on table \"%2\" row %4 (%5)"),
807 _T("Generated when table threshold is deactivated.\r\n")
808 _T("Parameters:\r\n")
809 _T(" 1) Table DCI name\r\n")
810 _T(" 2) Table DCI description\r\n")
811 _T(" 3) Table DCI ID\r\n")
812 _T(" 4) Table row\r\n")
813 _T(" 5) Instance")));
814
815 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='288' WHERE var_name='SchemaVersion'")));
816 return TRUE;
817}
818
9387bc59
VK
819/**
820 * Upgrade from V286 to V287
821 */
822static BOOL H_UpgradeFromV286(int currVersion, int newVersion)
823{
824 static TCHAR batch[] =
825 _T("ALTER TABLE dc_table_columns ADD sequence_number integer\n")
826 _T("UPDATE dc_table_columns SET sequence_number=0\n")
827 _T("<END>");
828 CHK_EXEC(SQLBatch(batch));
829
830 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='287' WHERE var_name='SchemaVersion'")));
831 return TRUE;
832}
833
9098ad59
VK
834/**
835 * Upgrade from V285 to V286
836 */
837static BOOL H_UpgradeFromV285(int currVersion, int newVersion)
838{
839 CHK_EXEC(CreateTable(
840 _T("CREATE TABLE dct_thresholds (")
841 _T("id integer not null,")
842 _T("table_id integer not null,")
843 _T("sequence_number integer not null,")
844 _T("current_state char(1) not null,")
845 _T("activation_event integer not null,")
846 _T("deactivation_event integer not null,")
847 _T("PRIMARY KEY(id))")));
848
849 CHK_EXEC(CreateTable(
850 _T("CREATE TABLE dct_threshold_conditions (")
851 _T("threshold_id integer not null,")
852 _T("group_id integer not null,")
853 _T("sequence_number integer not null,")
854 _T("column_name varchar(63) null,")
855 _T("check_operation integer not null,")
856 _T("check_value varchar(255) null,")
857 _T("PRIMARY KEY(threshold_id,group_id,sequence_number))")));
858
859 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='286' WHERE var_name='SchemaVersion'")));
860 return TRUE;
861}
862
17017844
VK
863/**
864 * Upgrade from V284 to V285
865 */
866static BOOL H_UpgradeFromV284(int currVersion, int newVersion)
867{
868 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_items_node_id ON items(node_id)")));
869 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_dc_tables_node_id ON dc_tables(node_id)")));
870
871 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='285' WHERE var_name='SchemaVersion'")));
872 return TRUE;
873}
874
eb4822b6
VK
875/**
876 * Upgrade from V283 to V284
877 */
878static BOOL H_UpgradeFromV283(int currVersion, int newVersion)
879{
880 CHK_EXEC(CreateConfigParam(_T("SNMPTrapPort"), _T("162"), 1, 1));
881
882 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='284' WHERE var_name='SchemaVersion'")));
883 return TRUE;
884}
885
0b77b73e
VK
886/**
887 * Upgrade from V282 to V283
888 */
889static BOOL H_UpgradeFromV282(int currVersion, int newVersion)
890{
891 static TCHAR batch[] =
892 _T("ALTER TABLE dc_table_columns ADD display_name varchar(255)\n")
893 _T("UPDATE dc_table_columns SET display_name=column_name\n")
894 _T("<END>");
895 CHK_EXEC(SQLBatch(batch));
896
897 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='283' WHERE var_name='SchemaVersion'")));
898 return TRUE;
899}
900
549f48b3
VK
901/**
902 * Upgrade from V281 to V282
903 */
904static BOOL H_UpgradeFromV281(int currVersion, int newVersion)
905{
906 CHK_EXEC(SQLQuery(_T("DELETE FROM config WHERE var_name='WindowsConsoleUpgradeURL'")));
907 CHK_EXEC(CreateConfigParam(_T("EnableObjectTransactions"), _T("0"), 1, 1));
908
909 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='282' WHERE var_name='SchemaVersion'")));
910 return TRUE;
911}
912
22aaa779
VK
913/**
914 * Upgrade from V280 to V281
915 */
916static BOOL H_UpgradeFromV280(int currVersion, int newVersion)
917{
918 static TCHAR batch[] =
919 _T("DELETE FROM metadata WHERE var_name='TDataTableCreationCommand'\n")
920 _T("INSERT INTO metadata (var_name,var_value)")
921 _T(" VALUES ('TDataTableCreationCommand_0','CREATE TABLE tdata_%d (item_id integer not null,tdata_timestamp integer not null,record_id $SQL:INT64 not null)')\n")
922 _T("INSERT INTO metadata (var_name,var_value)")
923 _T(" VALUES ('TDataTableCreationCommand_1','CREATE TABLE tdata_records_%d (record_id $SQL:INT64 not null,row_id $SQL:INT64 not null,instance varchar(255) null,PRIMARY KEY(record_id,row_id))')\n")
924 _T("INSERT INTO metadata (var_name,var_value)")
925 _T(" VALUES ('TDataTableCreationCommand_2','CREATE TABLE tdata_rows_%d (row_id $SQL:INT64 not null,column_id integer not null,value varchar(255) null,PRIMARY KEY(row_id,column_id))')\n")
926 _T("INSERT INTO metadata (var_name,var_value)")
927 _T(" VALUES ('TDataIndexCreationCommand_1','CREATE INDEX idx_tdata_rec_%d_instance ON tdata_records_%d(instance)')\n")
928 _T("<END>");
929 CHK_EXEC(SQLBatch(batch));
930
1d4f7890
VK
931 RecreateTData(_T("nodes"), false);
932 RecreateTData(_T("clusters"), false);
933 RecreateTData(_T("mobile_devices"), false);
22aaa779
VK
934
935 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='281' WHERE var_name='SchemaVersion'")));
936 return TRUE;
937}
938
939/**
940 * Upgrade from V279 to V280
941 */
942static BOOL H_UpgradeFromV279(int currVersion, int newVersion)
943{
944 static TCHAR batch[] =
945 _T("ALTER TABLE dc_table_columns ADD flags integer\n")
946 _T("UPDATE dc_table_columns SET flags=data_type\n")
947 _T("ALTER TABLE dc_table_columns DROP COLUMN data_type\n")
948 _T("<END>");
949 CHK_EXEC(SQLBatch(batch));
950
951 DB_RESULT hResult = SQLSelect(_T("SELECT item_id,instance_column FROM dc_tables"));
952 if (hResult != NULL)
953 {
954 int count = DBGetNumRows(hResult);
955 for(int i = 0; i < count; i++)
956 {
957 TCHAR columnName[MAX_COLUMN_NAME] = _T("");
958 DBGetField(hResult, i, 1, columnName, MAX_COLUMN_NAME);
959 if (columnName[0] != 0)
960 {
961 TCHAR query[256];
962 _sntprintf(query, 256, _T("UPDATE dc_table_columns SET flags=flags+256 WHERE table_id=%d AND column_name=%s"),
963 DBGetFieldLong(hResult, i, 0), (const TCHAR *)DBPrepareString(g_hCoreDB, columnName));
964 CHK_EXEC(SQLQuery(query));
965 }
966 }
967 DBFreeResult(hResult);
968 }
969 else
970 {
971 if (!g_bIgnoreErrors)
972 return FALSE;
973 }
974
975 CHK_EXEC(SQLQuery(_T("ALTER TABLE dc_tables DROP COLUMN instance_column")));
976
977 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='280' WHERE var_name='SchemaVersion'")));
978 return TRUE;
979}
980
22ee6d97
VK
981/**
982 * Upgrade from V278 to V279
983 */
984static BOOL H_UpgradeFromV278(int currVersion, int newVersion)
985{
986 CHK_EXEC(CreateConfigParam(_T("DeleteEventsOfDeletedObject"), _T("1"), 1, 0));
987 CHK_EXEC(CreateConfigParam(_T("DeleteAlarmsOfDeletedObject"), _T("1"), 1, 0));
988
989 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='279' WHERE var_name='SchemaVersion'")));
990 return TRUE;
991}
992
85ae39bc
VK
993/**
994 * Upgrade from V277 to V278
995 */
996static BOOL H_UpgradeFromV277(int currVersion, int newVersion)
997{
998 DB_RESULT hResult = SQLSelect(_T("SELECT id FROM clusters"));
999 if (hResult != NULL)
1000 {
1001 int count = DBGetNumRows(hResult);
1002 for(int i = 0; i < count; i++)
1003 {
1004 DWORD id = DBGetFieldULong(hResult, i, 0);
1005 if (!CreateIDataTable(id))
1006 {
1007 if (!g_bIgnoreErrors)
1008 {
1009 DBFreeResult(hResult);
1010 return FALSE;
1011 }
1012 }
22aaa779 1013 if (!CreateTDataTable_preV281(id))
85ae39bc
VK
1014 {
1015 if (!g_bIgnoreErrors)
1016 {
1017 DBFreeResult(hResult);
1018 return FALSE;
1019 }
1020 }
1021 }
1022 DBFreeResult(hResult);
1023 }
1024 else
1025 {
1026 if (!g_bIgnoreErrors)
1027 return FALSE;
1028 }
1029
1030 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='278' WHERE var_name='SchemaVersion'")));
1031 return TRUE;
1032}
1033
62f41164
VK
1034/**
1035 * Upgrade from V276 to V277
1036 */
1037static BOOL H_UpgradeFromV276(int currVersion, int newVersion)
1038{
b4c2a628
VK
1039 CHK_EXEC(CreateTable(_T("CREATE TABLE dci_summary_tables (")
1040 _T("id integer not null,")
1041 _T("menu_path varchar(255) not null,")
1042 _T("title varchar(127) null,")
1043 _T("node_filter $SQL:TEXT null,")
1044 _T("flags integer not null,")
1045 _T("columns $SQL:TEXT null,")
1046 _T("PRIMARY KEY(id))")));
1047
62f41164
VK
1048 CHK_EXEC(CreateConfigParam(_T("DefaultMapBackgroundColor"), _T("0xffffff"), 1, 0));
1049
1050 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='277' WHERE var_name='SchemaVersion'")));
1051 return TRUE;
1052}
1053
55bdca5a
VK
1054/**
1055 * Upgrade from V275 to V276
1056 */
1057static BOOL H_UpgradeFromV275(int currVersion, int newVersion)
1058{
1059 static TCHAR batch[] =
1060 _T("ALTER TABLE dc_table_columns DROP COLUMN transformation_script\n")
1061 _T("ALTER TABLE dc_tables ADD transformation_script $SQL:TEXT\n")
1062 _T("<END>");
1063 CHK_EXEC(SQLBatch(batch));
1064
1065 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='276' WHERE var_name='SchemaVersion'")));
1066 return TRUE;
1067}
1068
8715a84c
VK
1069/**
1070 * Upgrade from V274 to V275
1071 */
1072static BOOL H_UpgradeFromV274(int currVersion, int newVersion)
1073{
1074 static TCHAR batch[] =
1075 _T("ALTER TABLE nodes ADD rack_image varchar(36)\n")
1076 _T("ALTER TABLE nodes ADD rack_position integer\n")
1077 _T("ALTER TABLE nodes ADD rack_id integer\n")
1078 _T("UPDATE nodes SET rack_image='00000000-0000-0000-0000-000000000000',rack_position=0,rack_id=0\n")
1079 _T("<END>");
1080 CHK_EXEC(SQLBatch(batch));
1081
1082 CHK_EXEC(CreateTable(_T("CREATE TABLE access_points (")
1083 _T("id integer not null,")
1084 _T("node_id integer not null,")
f1989a3a 1085 _T("mac_address varchar(12) null,")
8715a84c
VK
1086 _T("vendor varchar(64) null,")
1087 _T("model varchar(128) null,")
1088 _T("serial_number varchar(64) null,")
1089 _T("PRIMARY KEY(id))")));
1090
1091 CHK_EXEC(CreateTable(_T("CREATE TABLE racks (")
1092 _T("id integer not null,")
1093 _T("height integer not null,")
1094 _T("PRIMARY KEY(id))")));
1095
1096 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='275' WHERE var_name='SchemaVersion'")));
1097 return TRUE;
1098}
1099
d02f6b92
VK
1100/**
1101 * Upgrade from V273 to V274
1102 */
1103static BOOL H_UpgradeFromV273(int currVersion, int newVersion)
1104{
1105 static TCHAR batch[] =
1106 _T("ALTER TABLE items ADD samples integer\n")
1107 _T("UPDATE items SET samples=0\n")
1108 _T("<END>");
1109 CHK_EXEC(SQLBatch(batch));
1110
1111 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='274' WHERE var_name='SchemaVersion'")));
1112 return TRUE;
1113}
1114
f05a8a45
VK
1115/**
1116 * Upgrade from V272 to V273
1117 */
1118static BOOL H_UpgradeFromV272(int currVersion, int newVersion)
1119{
1120 CHK_EXEC(CreateConfigParam(_T("DefaultDCIRetentionTime"), _T("30"), 1, 0));
1121 CHK_EXEC(CreateConfigParam(_T("DefaultDCIPollingInterval"), _T("60"), 1, 0));
1122 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='273' WHERE var_name='SchemaVersion'")));
1123 return TRUE;
1124}
1125
0f75f8fc
VK
1126/**
1127 * Upgrade from V271 to V272
1128 */
1129static BOOL H_UpgradeFromV271(int currVersion, int newVersion)
1130{
1131 CHK_EXEC(CreateConfigParam(_T("SNMPTrapLogRetentionTime"), _T("90"), 1, 0));
28e1575f 1132 CHK_EXEC(SQLQuery(_T("ALTER TABLE nodes ADD driver_name varchar(32)\n")));
0f75f8fc
VK
1133 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='272' WHERE var_name='SchemaVersion'")));
1134 return TRUE;
1135}
1136
86634c2c
VK
1137/**
1138 * Upgrade from V270 to V271
1139 */
1140static BOOL H_UpgradeFromV270(int currVersion, int newVersion)
1141{
1142 static TCHAR batch[] =
1143 _T("ALTER TABLE object_properties ADD location_accuracy integer\n")
f2d5b2c4
VK
1144 _T("ALTER TABLE object_properties ADD location_timestamp integer\n")
1145 _T("UPDATE object_properties SET location_accuracy=0,location_timestamp=0\n")
86634c2c
VK
1146 _T("<END>");
1147 CHK_EXEC(SQLBatch(batch));
1148
1149 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='271' WHERE var_name='SchemaVersion'")));
1150 return TRUE;
1151}
1152
afbe5388
VK
1153/**
1154 * Upgrade from V269 to V270
1155 */
1156static BOOL H_UpgradeFromV269(int currVersion, int newVersion)
1157{
6f33021d 1158 static TCHAR batch[] =
afbe5388
VK
1159 _T("ALTER TABLE items ADD instd_method integer\n")
1160 _T("ALTER TABLE items ADD instd_data varchar(255)\n")
1161 _T("ALTER TABLE items ADD instd_filter $SQL:TEXT\n")
1162 _T("UPDATE items SET instd_method=0\n")
1163 _T("<END>");
1164 CHK_EXEC(SQLBatch(batch));
1165
1166 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='270' WHERE var_name='SchemaVersion'")));
1167 return TRUE;
1168}
1169
480e036b
VK
1170/**
1171 * Upgrade from V268 to V269
1172 */
1173static BOOL H_UpgradeFromV268(int currVersion, int newVersion)
1174{
1175 CHK_EXEC(ResizeColumn(_T("alarms"), _T("message"), 2000));
1176 CHK_EXEC(ResizeColumn(_T("alarm_events"), _T("message"), 2000));
1177 CHK_EXEC(ResizeColumn(_T("event_log"), _T("event_message"), 2000));
1178 CHK_EXEC(ResizeColumn(_T("event_cfg"), _T("message"), 2000));
1179 CHK_EXEC(ResizeColumn(_T("event_policy"), _T("alarm_message"), 2000));
1180 CHK_EXEC(ResizeColumn(_T("items"), _T("name"), 1024));
1181 CHK_EXEC(ResizeColumn(_T("dc_tables"), _T("name"), 1024));
1182
1183 CHK_EXEC(SetColumnNullable(_T("event_policy"), _T("alarm_key")));
1184 CHK_EXEC(SetColumnNullable(_T("event_policy"), _T("alarm_message")));
1185 CHK_EXEC(SetColumnNullable(_T("event_policy"), _T("comments")));
1186 CHK_EXEC(SetColumnNullable(_T("event_policy"), _T("situation_instance")));
1187 CHK_EXEC(SetColumnNullable(_T("event_policy"), _T("script")));
1188 CHK_EXEC(ConvertStrings(_T("event_policy"), _T("rule_id"), _T("alarm_key")));
1189 CHK_EXEC(ConvertStrings(_T("event_policy"), _T("rule_id"), _T("alarm_message")));
1190 CHK_EXEC(ConvertStrings(_T("event_policy"), _T("rule_id"), _T("comments")));
1191 CHK_EXEC(ConvertStrings(_T("event_policy"), _T("rule_id"), _T("situation_instance")));
1192 CHK_EXEC(ConvertStrings(_T("event_policy"), _T("rule_id"), _T("script")));
1193
1194 CHK_EXEC(SetColumnNullable(_T("policy_situation_attr_list"), _T("attr_value")));
1195 // convert strings in policy_situation_attr_list
1196 DB_RESULT hResult = SQLSelect(_T("SELECT rule_id,situation_id,attr_name,attr_value FROM policy_situation_attr_list"));
1197 if (hResult != NULL)
1198 {
1199 if (SQLQuery(_T("DELETE FROM policy_situation_attr_list")))
1200 {
1201 TCHAR name[MAX_DB_STRING], value[MAX_DB_STRING], query[1024];
1202 int count = DBGetNumRows(hResult);
1203 for(int i = 0; i < count; i++)
1204 {
1205 LONG ruleId = DBGetFieldLong(hResult, i, 0);
1206 LONG situationId = DBGetFieldLong(hResult, i, 1);
1207 DBGetField(hResult, i, 2, name, MAX_DB_STRING);
1208 DBGetField(hResult, i, 3, value, MAX_DB_STRING);
1209
1210 DecodeSQLString(name);
1211 DecodeSQLString(value);
1212
1213 if (name[0] == 0)
1214 _tcscpy(name, _T("noname"));
1215
1216 _sntprintf(query, 1024, _T("INSERT INTO policy_situation_attr_list (rule_id,situation_id,attr_name,attr_value) VALUES (%d,%d,%s,%s)"),
1217 ruleId, situationId, (const TCHAR *)DBPrepareString(g_hCoreDB, name), (const TCHAR *)DBPrepareString(g_hCoreDB, value));
1218 if (!SQLQuery(query))
1219 {
1220 if (!g_bIgnoreErrors)
1221 {
1222 DBFreeResult(hResult);
1223 return FALSE;
1224 }
1225 }
1226 }
1227 }
1228 else
1229 {
1230 if (!g_bIgnoreErrors)
1231 {
1232 DBFreeResult(hResult);
1233 return FALSE;
1234 }
1235 }
1236 DBFreeResult(hResult);
1237 }
1238 else
1239 {
1240 if (!g_bIgnoreErrors)
1241 return FALSE;
1242 }
1243
1244 CHK_EXEC(SetColumnNullable(_T("event_cfg"), _T("description")));
1245 CHK_EXEC(SetColumnNullable(_T("event_cfg"), _T("message")));
1246 CHK_EXEC(ConvertStrings(_T("event_cfg"), _T("event_code"), _T("description")));
1247 CHK_EXEC(ConvertStrings(_T("event_cfg"), _T("event_code"), _T("message")));
1248
1249 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='269' WHERE var_name='SchemaVersion'")));
1250 return TRUE;
1251}
1252
d6bf58f9
VK
1253/**
1254 * Upgrade from V267 to V268
1255 */
1256static BOOL H_UpgradeFromV267(int currVersion, int newVersion)
1257{
480e036b
VK
1258 CHK_EXEC(SetColumnNullable(_T("network_services"), _T("check_request")));
1259 CHK_EXEC(SetColumnNullable(_T("network_services"), _T("check_responce")));
d6bf58f9
VK
1260 CHK_EXEC(ConvertStrings(_T("network_services"), _T("id"), _T("check_request")));
1261 CHK_EXEC(ConvertStrings(_T("network_services"), _T("id"), _T("check_responce")));
1262
480e036b 1263 CHK_EXEC(SetColumnNullable(_T("config"), _T("var_value")));
d6bf58f9
VK
1264 CHK_EXEC(ConvertStrings(_T("config"), _T("var_name"), NULL, _T("var_value"), true));
1265
480e036b 1266 CHK_EXEC(SetColumnNullable(_T("dci_schedules"), _T("schedule")));
d6bf58f9
VK
1267 CHK_EXEC(ConvertStrings(_T("dci_schedules"), _T("schedule_id"), _T("item_id"), _T("schedule"), false));
1268
1269 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='268' WHERE var_name='SchemaVersion'")));
1270 return TRUE;
1271}
1272
c1482463
VK
1273/**
1274 * Upgrade from V266 to V267
1275 */
1276static BOOL H_UpgradeFromV266(int currVersion, int newVersion)
1277{
1278 CHK_EXEC(CreateEventTemplate(EVENT_NODE_UNREACHABLE, _T("SYS_NODE_UNREACHABLE"), EVENT_SEVERITY_CRITICAL,
1279 EF_LOG, _T("Node unreachable because of network failure"),
1280 _T("Generated when node is unreachable by management server because of network failure.\r\nParameters:\r\n No event-specific parameters")));
1281 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='267' WHERE var_name='SchemaVersion'")));
1282 return TRUE;
1283}
1284
69bb7f47
VK
1285/**
1286 * Upgrade from V265 to V266
1287 */
1288static BOOL H_UpgradeFromV265(int currVersion, int newVersion)
1289{
1290 // create index on root event ID in event log
1291 switch(g_iSyntax)
1292 {
1293 case DB_SYNTAX_MSSQL:
1294 case DB_SYNTAX_PGSQL:
1295 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_event_log_root_id ON event_log(root_event_id) WHERE root_event_id > 0")));
1296 break;
1297 case DB_SYNTAX_ORACLE:
1298 CHK_EXEC(SQLQuery(_T("CREATE OR REPLACE FUNCTION zero_to_null(id NUMBER) ")
1299 _T("RETURN NUMBER ")
1300 _T("DETERMINISTIC ")
1301 _T("AS BEGIN")
1302 _T(" IF id > 0 THEN")
1303 _T(" RETURN id;")
1304 _T(" ELSE")
1305 _T(" RETURN NULL;")
1306 _T(" END IF;")
1307 _T("END;")));
1308 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_event_log_root_id ON event_log(zero_to_null(root_event_id))")));
1309 break;
1310 default:
1311 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_event_log_root_id ON event_log(root_event_id)")));
1312 break;
1313 }
1314
1315 CHK_EXEC(CreateTable(_T("CREATE TABLE mapping_tables (")
1316 _T("id integer not null,")
1317 _T("name varchar(63) not null,")
1318 _T("flags integer not null,")
1319 _T("description $SQL:TXT4K null,")
1320 _T("PRIMARY KEY(id))")));
1321
1322 CHK_EXEC(CreateTable(_T("CREATE TABLE mapping_data (")
1323 _T("table_id integer not null,")
1324 _T("md_key varchar(63) not null,")
1325 _T("md_value varchar(255) null,")
f41af2c4 1326 _T("description $SQL:TXT4K null,")
69bb7f47
VK
1327 _T("PRIMARY KEY(table_id,md_key))")));
1328
1329 CHK_EXEC(SQLQuery(_T("DROP TABLE deleted_objects")));
1330
1331 CHK_EXEC(CreateConfigParam(_T("FirstFreeObjectId"), _T("100"), 0, 1, FALSE));
1332
1333 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='266' WHERE var_name='SchemaVersion'")));
1334 return TRUE;
1335}
1336
b1e9b6b3
VK
1337/**
1338 * Upgrade from V264 to V265
1339 */
1340static BOOL H_UpgradeFromV264(int currVersion, int newVersion)
1341{
1342 CHK_EXEC(CreateTable(_T("CREATE TABLE alarm_events (")
1343 _T("alarm_id integer not null,")
1344 _T("event_id $SQL:INT64 not null,")
1345 _T("event_code integer not null,")
1346 _T("event_name varchar(63) null,")
1347 _T("severity integer not null,")
1348 _T("source_object_id integer not null,")
1349 _T("event_timestamp integer not null,")
1350 _T("message varchar(255) null,")
1351 _T("PRIMARY KEY(alarm_id,event_id))")));
1352 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_alarm_events_alarm_id ON alarm_events(alarm_id)")));
1353 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='265' WHERE var_name='SchemaVersion'")));
1354 return TRUE;
1355}
1356
9aa67910
VK
1357/**
1358 * Upgrade from V263 to V264
1359 */
1360static BOOL H_UpgradeFromV263(int currVersion, int newVersion)
1361{
1362 CHK_EXEC(CreateTable(_T("CREATE TABLE mobile_devices (")
1363 _T("id integer not null,")
1364 _T("device_id varchar(64) not null,")
1365 _T("vendor varchar(64) null,")
1366 _T("model varchar(128) null,")
1367 _T("serial_number varchar(64) null,")
1368 _T("os_name varchar(32) null,")
1369 _T("os_version varchar(64) null,")
1370 _T("user_id varchar(64) null,")
171c2fd6 1371 _T("battery_level integer not null,")
9aa67910 1372 _T("PRIMARY KEY(id))")));
534e1b83 1373 CHK_EXEC(CreateConfigParam(_T("MobileDeviceListenerPort"), _T("4747"), 1, 1));
9aa67910
VK
1374 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='264' WHERE var_name='SchemaVersion'")));
1375 return TRUE;
1376}
1377
84880c89
VK
1378/**
1379 * Upgrade from V262 to V263
1380 */
1381static BOOL H_UpgradeFromV262(int currVersion, int newVersion)
1382{
1383 CHK_EXEC(SQLQuery(_T("ALTER TABLE network_maps ADD radius integer")));
1384 CHK_EXEC(SQLQuery(_T("UPDATE network_maps SET radius=-1")));
1385 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='263' WHERE var_name='SchemaVersion'")));
1386 return TRUE;
1387}
1388
dc4a1aec
AK
1389/**
1390 * Upgrade from V261 to V262
1391 */
1392static BOOL H_UpgradeFromV261(int currVersion, int newVersion)
1393{
534e1b83 1394 CHK_EXEC(CreateConfigParam(_T("ApplyDCIFromTemplateToDisabledDCI"), _T("0"), 1, 1));
dc4a1aec
AK
1395 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='262' WHERE var_name='SchemaVersion'")));
1396 return TRUE;
1397}
1398
4f50e45c
VK
1399/**
1400 * Upgrade from V260 to V261
1401 */
1402static BOOL H_UpgradeFromV260(int currVersion, int newVersion)
1403{
534e1b83 1404 CHK_EXEC(CreateConfigParam(_T("NumberOfBusinessServicePollers"), _T("10"), 1, 1));
4f50e45c
VK
1405 CHK_EXEC(SQLQuery(_T("DELETE FROM config WHERE var_name='NumberOfEventProcessors'")));
1406 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='261' WHERE var_name='SchemaVersion'")));
1407 return TRUE;
1408}
a203ea53 1409
4f50e45c
VK
1410/**
1411 * Upgrade from V259 to V260
1412 */
a203ea53
AK
1413static BOOL H_UpgradeFromV259(int currVersion, int newVersion)
1414{
534e1b83 1415 CHK_EXEC(CreateConfigParam(_T("UseFQDNForNodeNames"), _T("1"), 1, 1));
a203ea53
AK
1416 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='260' WHERE var_name='SchemaVersion'")));
1417 return TRUE;
1418}
1419
4f50e45c
VK
1420/**
1421 * Upgrade from V258 to V259
1422 */
5da6ca46
VK
1423static BOOL H_UpgradeFromV258(int currVersion, int newVersion)
1424{
1425 // have to made these columns nullable again because
1426 // because they was forgotten as NOT NULL in schema.in
1427 // and so some databases can still have them as NOT NULL
480e036b
VK
1428 CHK_EXEC(SetColumnNullable(_T("templates"), _T("apply_filter")));
1429 CHK_EXEC(SetColumnNullable(_T("containers"), _T("auto_bind_filter")));
5da6ca46
VK
1430
1431 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='259' WHERE var_name='SchemaVersion'")));
1432 return TRUE;
1433}
1434
4f50e45c
VK
1435/**
1436 * Upgrade from V257 to V258
1437 */
dd42ad0a
AK
1438static BOOL H_UpgradeFromV257(int currVersion, int newVersion)
1439{
6f33021d 1440 static TCHAR batch[] =
dd42ad0a
AK
1441 _T("ALTER TABLE nodes ADD down_since integer\n")
1442 _T("UPDATE nodes SET down_since=0\n")
1443 _T("<END>");
1444
1445 CHK_EXEC(SQLBatch(batch));
1446
534e1b83 1447 CHK_EXEC(CreateConfigParam(_T("DeleteUnreachableNodesPeriod"), _T("0"), 1, 1));
dd42ad0a
AK
1448
1449 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='258' WHERE var_name='SchemaVersion'")));
1450 return TRUE;
1451}
aa16f82b 1452
534e1b83
VK
1453/**
1454 * Upgrade from V256 to V257
1455 */
e4acd770
VK
1456static BOOL H_UpgradeFromV256(int currVersion, int newVersion)
1457{
6f33021d 1458 static TCHAR batch[] =
e4acd770
VK
1459 _T("ALTER TABLE network_maps ADD bg_color integer\n")
1460 _T("ALTER TABLE network_maps ADD link_routing integer\n")
1461 _T("UPDATE network_maps SET bg_color=16777215,link_routing=1\n")
1462 _T("ALTER TABLE network_map_links ADD routing integer\n")
1463 _T("ALTER TABLE network_map_links ADD bend_points $SQL:TXT4K\n")
1464 _T("UPDATE network_map_links SET routing=0\n")
1465 _T("<END>");
1466
1467 CHK_EXEC(SQLBatch(batch));
6f33021d 1468
e4acd770
VK
1469 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='257' WHERE var_name='SchemaVersion'")));
1470 return TRUE;
1471}
1472
534e1b83
VK
1473/**
1474 * Upgrade from V255 to V256
1475 */
aabe5b72
VK
1476static BOOL H_UpgradeFromV255(int currVersion, int newVersion)
1477{
534e1b83
VK
1478 CHK_EXEC(CreateConfigParam(_T("DefaultConsoleDateFormat"), _T("dd.MM.yyyy"), 1, 0));
1479 CHK_EXEC(CreateConfigParam(_T("DefaultConsoleTimeFormat"), _T("HH:mm:ss"), 1, 0));
aabe5b72
VK
1480
1481 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='256' WHERE var_name='SchemaVersion'")));
1482 return TRUE;
1483}
1484
480e036b
VK
1485/**
1486 * Upgrade from V254 to V255
1487 */
5f6bc78c
VK
1488static BOOL H_UpgradeFromV254(int currVersion, int newVersion)
1489{
6f33021d 1490 static TCHAR batch[] =
5f6bc78c
VK
1491 _T("ALTER TABLE alarms ADD resolved_by integer\n")
1492 _T("UPDATE alarms SET resolved_by=0\n")
1493 _T("UPDATE alarms SET alarm_state=3 WHERE alarm_state=2\n")
1494 _T("<END>");
1495
1496 CHK_EXEC(SQLBatch(batch));
1497
3e9e0cc5 1498 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='255' WHERE var_name='SchemaVersion'")));
5f6bc78c
VK
1499 return TRUE;
1500}
40647141 1501
badf9a95
VK
1502/**
1503 * Upgrade from V253 to V254
1504 */
40647141
VK
1505static BOOL H_UpgradeFromV253(int currVersion, int newVersion)
1506{
6f33021d 1507 static TCHAR batch[] =
40647141
VK
1508 _T("ALTER TABLE network_maps ADD flags integer\n")
1509 _T("ALTER TABLE network_maps ADD link_color integer\n")
1510 _T("UPDATE network_maps SET flags=1,link_color=-1\n")
1511 _T("ALTER TABLE network_map_links ADD color integer\n")
1512 _T("ALTER TABLE network_map_links ADD status_object integer\n")
1513 _T("UPDATE network_map_links SET color=-1,status_object=0\n")
1514 _T("<END>");
1515
1516 CHK_EXEC(SQLBatch(batch));
1517
1518 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='254' WHERE var_name='SchemaVersion'")));
1519 return TRUE;
1520}
1521
d6bf58f9
VK
1522/**
1523 * Upgrade from V252 to V253
1524 */
feab3324
VK
1525static BOOL H_UpgradeFromV252(int currVersion, int newVersion)
1526{
480e036b 1527 CHK_EXEC(SetColumnNullable(_T("templates"), _T("apply_filter")));
242e9c7f
VK
1528 CHK_EXEC(ConvertStrings(_T("templates"), _T("id"), _T("apply_filter")));
1529
480e036b 1530 CHK_EXEC(SetColumnNullable(_T("containers"), _T("auto_bind_filter")));
242e9c7f
VK
1531 CHK_EXEC(ConvertStrings(_T("containers"), _T("id"), _T("auto_bind_filter")));
1532
6f33021d 1533 static TCHAR batch[] =
feab3324 1534 _T("ALTER TABLE templates ADD flags integer\n")
2984ac95
VK
1535 _T("UPDATE templates SET flags=0 WHERE enable_auto_apply=0\n")
1536 _T("UPDATE templates SET flags=3 WHERE enable_auto_apply<>0\n")
feab3324
VK
1537 _T("ALTER TABLE templates DROP COLUMN enable_auto_apply\n")
1538 _T("ALTER TABLE containers ADD flags integer\n")
2984ac95
VK
1539 _T("UPDATE containers SET flags=0 WHERE enable_auto_bind=0\n")
1540 _T("UPDATE containers SET flags=3 WHERE enable_auto_bind<>0\n")
feab3324
VK
1541 _T("ALTER TABLE containers DROP COLUMN enable_auto_bind\n")
1542 _T("<END>");
feab3324
VK
1543 CHK_EXEC(SQLBatch(batch));
1544
1545 CHK_EXEC(CreateEventTemplate(EVENT_CONTAINER_AUTOBIND, _T("SYS_CONTAINER_AUTOBIND"), EVENT_SEVERITY_NORMAL, 1,
6f33021d 1546 _T("Node %2 automatically bound to container %4"),
feab3324
VK
1547 _T("Generated when node bound to container object by autobind rule.\r\n")
1548 _T("Parameters:#\r\n")
1549 _T(" 1) Node ID\r\n")
1550 _T(" 2) Node name\r\n")
1551 _T(" 3) Container ID\r\n")
1552 _T(" 4) Container name")
1553 ));
1554
1555 CHK_EXEC(CreateEventTemplate(EVENT_CONTAINER_AUTOUNBIND, _T("SYS_CONTAINER_AUTOUNBIND"), EVENT_SEVERITY_NORMAL, 1,
6f33021d 1556 _T("Node %2 automatically unbound from container %4"),
feab3324
VK
1557 _T("Generated when node unbound from container object by autobind rule.\r\n")
1558 _T("Parameters:#\r\n")
1559 _T(" 1) Node ID\r\n")
1560 _T(" 2) Node name\r\n")
1561 _T(" 3) Container ID\r\n")
1562 _T(" 4) Container name")
1563 ));
1564
1565 CHK_EXEC(CreateEventTemplate(EVENT_TEMPLATE_AUTOAPPLY, _T("SYS_TEMPLATE_AUTOAPPLY"), EVENT_SEVERITY_NORMAL, 1,
6f33021d 1566 _T("Template %4 automatically applied to node %2"),
feab3324
VK
1567 _T("Generated when template applied to node by autoapply rule.\r\n")
1568 _T("Parameters:#\r\n")
1569 _T(" 1) Node ID\r\n")
1570 _T(" 2) Node name\r\n")
1571 _T(" 3) Template ID\r\n")
1572 _T(" 4) Template name")
1573 ));
1574
1575 CHK_EXEC(CreateEventTemplate(EVENT_TEMPLATE_AUTOREMOVE, _T("SYS_TEMPLATE_AUTOREMOVE"), EVENT_SEVERITY_NORMAL, 1,
6f33021d 1576 _T("Template %4 automatically removed from node %2"),
feab3324
VK
1577 _T("Generated when template removed from node by autoapply rule.\r\n")
1578 _T("Parameters:#\r\n")
1579 _T(" 1) Node ID\r\n")
1580 _T(" 2) Node name\r\n")
1581 _T(" 3) Template ID\r\n")
1582 _T(" 4) Template name")
1583 ));
1584
65790062
VK
1585 TCHAR buffer[64];
1586 _sntprintf(buffer, 64, _T("%d"), ConfigReadInt(_T("AllowedCiphers"), 15) + 16);
1587 CreateConfigParam(_T("AllowedCiphers"), buffer, 1, 1, TRUE);
1588
feab3324
VK
1589 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='253' WHERE var_name='SchemaVersion'")));
1590 return TRUE;
1591}
1592
badf9a95
VK
1593/**
1594 * Upgrade from V251 to V252
1595 */
1e6b68a6
VK
1596static BOOL H_UpgradeFromV251(int currVersion, int newVersion)
1597{
6f33021d 1598 static TCHAR batch[] =
1e6b68a6
VK
1599 _T("ALTER TABLE interfaces ADD admin_state integer\n")
1600 _T("ALTER TABLE interfaces ADD oper_state integer\n")
1601 _T("UPDATE interfaces SET admin_state=0,oper_state=0\n")
1602 _T("<END>");
1603
1604 CHK_EXEC(SQLBatch(batch));
1605
1606 CHK_EXEC(CreateEventTemplate(EVENT_INTERFACE_UNEXPECTED_UP, _T("SYS_IF_UNEXPECTED_UP"), EVENT_SEVERITY_MAJOR, 1,
6f33021d 1607 _T("Interface \"%2\" unexpectedly changed state to UP (IP Addr: %3/%4, IfIndex: %5)"),
1e6b68a6
VK
1608 _T("Generated when interface goes up but it's expected state set to DOWN.\r\n")
1609 _T("Please note that source of event is node, not an interface itself.\r\n")
1610 _T("Parameters:#\r\n")
1611 _T(" 1) Interface object ID\r\n")
1612 _T(" 2) Interface name\r\n")
1613 _T(" 3) Interface IP address\r\n")
1614 _T(" 4) Interface netmask\r\n")
1615 _T(" 5) Interface index")
1616 ));
1617
1618 CHK_EXEC(CreateEventTemplate(EVENT_INTERFACE_EXPECTED_DOWN, _T("SYS_IF_EXPECTED_DOWN"), EVENT_SEVERITY_NORMAL, 1,
6f33021d 1619 _T("Interface \"%2\" with expected state DOWN changed state to DOWN (IP Addr: %3/%4, IfIndex: %5)"),
1e6b68a6
VK
1620 _T("Generated when interface goes down and it's expected state is DOWN.\r\n")
1621 _T("Please note that source of event is node, not an interface itself.\r\n")
1622 _T("Parameters:#\r\n")
1623 _T(" 1) Interface object ID\r\n")
1624 _T(" 2) Interface name\r\n")
1625 _T(" 3) Interface IP address\r\n")
1626 _T(" 4) Interface netmask\r\n")
1627 _T(" 5) Interface index")
1628 ));
1629
1630 // Create rule pair in event processing policy
1631 int ruleId = 0;
1632 DB_RESULT hResult = SQLSelect(_T("SELECT max(rule_id) FROM event_policy"));
1633 if (hResult != NULL)
1634 {
1635 ruleId = DBGetFieldLong(hResult, 0, 0) + 1;
1636 DBFreeResult(hResult);
1637 }
1638
1639 TCHAR query[1024];
6f33021d 1640 _sntprintf(query, 1024,
1e6b68a6
VK
1641 _T("INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,")
1642 _T("script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES ")
1643 _T("(%d,7944,'Show alarm when interface is unexpectedly up','%%m',5,'IF_UNEXP_UP_%%i_%%1',")
1644 _T("'#00',0,%d,0,'#00')"), ruleId, EVENT_ALARM_TIMEOUT);
1645 CHK_EXEC(SQLQuery(query));
1646 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_INTERFACE_UNEXPECTED_UP);
1647 CHK_EXEC(SQLQuery(query));
1648 ruleId++;
1649
6f33021d 1650 _sntprintf(query, 1024,
1e6b68a6
VK
1651 _T("INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,")
1652 _T("script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES ")
1653 _T("(%d,7944,'Acknowlege interface unexpectedly up alarms when interface goes down','%%m',")
1654 _T("6,'IF_UNEXP_UP_%%i_%%1','#00',0,%d,0,'#00')"), ruleId, EVENT_ALARM_TIMEOUT);
1655 CHK_EXEC(SQLQuery(query));
1656 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_INTERFACE_EXPECTED_DOWN);
1657 CHK_EXEC(SQLQuery(query));
1658
1659 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='252' WHERE var_name='SchemaVersion'")));
1660 return TRUE;
1661}
1662
9aa67910
VK
1663/**
1664 * Upgrade from V250 to V251
1665 */
711e5e9a
VK
1666static BOOL H_UpgradeFromV250(int currVersion, int newVersion)
1667{
6f33021d 1668 static TCHAR batch[] =
711e5e9a
VK
1669 _T("ALTER TABLE thresholds ADD current_severity integer\n")
1670 _T("ALTER TABLE thresholds ADD last_event_timestamp integer\n")
1671 _T("UPDATE thresholds SET current_severity=0,last_event_timestamp=0\n")
1672 _T("<END>");
1673
1674 CHK_EXEC(SQLBatch(batch));
1675
480e036b
VK
1676 CHK_EXEC(SetColumnNullable(_T("thresholds"), _T("fire_value")));
1677 CHK_EXEC(SetColumnNullable(_T("thresholds"), _T("rearm_value")));
711e5e9a
VK
1678 CHK_EXEC(ConvertStrings(_T("thresholds"), _T("threshold_id"), _T("fire_value")));
1679 CHK_EXEC(ConvertStrings(_T("thresholds"), _T("threshold_id"), _T("rearm_value")));
1680
1681 CHK_EXEC(CreateConfigParam(_T("EnableNXSLContainerFunctions"), _T("1"), 1, 1));
1682 CHK_EXEC(CreateConfigParam(_T("UseDNSNameForDiscoveredNodes"), _T("0"), 1, 0));
1683 CHK_EXEC(CreateConfigParam(_T("AllowTrapVarbindsConversion"), _T("1"), 1, 1));
1684
1685 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='251' WHERE var_name='SchemaVersion'")));
1686 return TRUE;
1687}
1688
9aa67910
VK
1689/**
1690 * Upgrade from V249 to V250
1691 */
ae2a3458
VK
1692static BOOL H_UpgradeFromV249(int currVersion, int newVersion)
1693{
1694 CHK_EXEC(CreateTable(_T("CREATE TABLE licenses (")
1695 _T("id integer not null,")
1696 _T("content $SQL:TEXT null,")
1697 _T("PRIMARY KEY(id))")));
1698
1699 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='250' WHERE var_name='SchemaVersion'")));
1700 return TRUE;
1701}
1702
9aa67910
VK
1703/**
1704 * Upgrade from V248 to V249
1705 */
d6124fa0
VK
1706#define TDATA_CREATE_QUERY _T("CREATE TABLE tdata_%d (item_id integer not null,tdata_timestamp integer not null,tdata_row integer not null,tdata_column integer not null,tdata_value varchar(255) null)")
1707#define TDATA_INDEX_MSSQL _T("CREATE CLUSTERED INDEX idx_tdata_%d_id_timestamp ON tdata_%d(item_id,tdata_timestamp)")
1708#define TDATA_INDEX_PGSQL _T("CREATE INDEX idx_tdata_%d_timestamp_id ON tdata_%d(tdata_timestamp,item_id)")
1709#define TDATA_INDEX_DEFAULT _T("CREATE INDEX idx_tdata_%d_id_timestamp ON tdata_%d(item_id,tdata_timestamp)")
1710
1711static BOOL CreateTData(DWORD nodeId)
1712{
1713 TCHAR query[256];
1714
1715 _sntprintf(query, 256, TDATA_CREATE_QUERY, (int)nodeId);
1716 CHK_EXEC(SQLQuery(query));
1717
1718 switch(g_iSyntax)
1719 {
1720 case DB_SYNTAX_MSSQL:
1721 _sntprintf(query, 256, TDATA_INDEX_MSSQL, (int)nodeId, (int)nodeId);
1722 break;
1723 case DB_SYNTAX_PGSQL:
1724 _sntprintf(query, 256, TDATA_INDEX_PGSQL, (int)nodeId, (int)nodeId);
1725 break;
1726 default:
1727 _sntprintf(query, 256, TDATA_INDEX_DEFAULT, (int)nodeId, (int)nodeId);
1728 break;
1729 }
1730 CHK_EXEC(SQLQuery(query));
1731
1732 return TRUE;
1733}
1734
1735static BOOL H_UpgradeFromV248(int currVersion, int newVersion)
1736{
1737 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataTableCreationCommand','") TDATA_CREATE_QUERY _T("')")));
1738
1739 switch(g_iSyntax)
1740 {
1741 case DB_SYNTAX_MSSQL:
1742 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataIndexCreationCommand_0','") TDATA_INDEX_MSSQL _T("')")));
1743 break;
1744 case DB_SYNTAX_PGSQL:
1745 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataIndexCreationCommand_0','") TDATA_INDEX_PGSQL _T("')")));
1746 break;
1747 default:
1748 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataIndexCreationCommand_0','") TDATA_INDEX_DEFAULT _T("')")));
1749 break;
1750 }
1751
1752 CHK_EXEC(CreateTable(_T("CREATE TABLE dct_column_names (")
1753 _T("column_id integer not null,")
1754 _T("column_name varchar(63) not null,")
1755 _T("PRIMARY KEY(column_id))")));
1756
1757 DB_RESULT hResult = SQLSelect(_T("SELECT id FROM nodes"));
1758 if (hResult != NULL)
1759 {
1760 int count = DBGetNumRows(hResult);
1761 for(int i = 0 ; i < count; i++)
1762 {
1763 if (!CreateTData(DBGetFieldULong(hResult, i, 0)))
1764 {
1765 if (!g_bIgnoreErrors)
1766 {
1767 DBFreeResult(hResult);
1768 return FALSE;
1769 }
1770 }
1771 }
1772 DBFreeResult(hResult);
1773 }
1774 else
1775 {
1776 if (!g_bIgnoreErrors)
1777 return FALSE;
1778 }
1779
1780 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='249' WHERE var_name='SchemaVersion'")));
1781 return TRUE;
1782}
1783
480e036b
VK
1784/**
1785 * Upgrade from V247 to V248
1786 */
cc8ce218
VK
1787static BOOL H_UpgradeFromV247(int currVersion, int newVersion)
1788{
1789 CHK_EXEC(CreateTable(_T("CREATE TABLE dc_tables (")
1790 _T("item_id integer not null,")
1791 _T("node_id integer not null,")
1792 _T("template_id integer not null,")
1793 _T("template_item_id integer not null,")
1794 _T("name varchar(255) null,")
1795 _T("instance_column varchar(63) null,")
1796 _T("description varchar(255) null,")
1797 _T("flags integer not null,")
1798 _T("source integer not null,")
1799 _T("snmp_port integer not null,")
1800 _T("polling_interval integer not null,")
1801 _T("retention_time integer not null,")
1802 _T("status integer not null,")
1803 _T("system_tag varchar(255) null,")
1804 _T("resource_id integer not null,")
1805 _T("proxy_node integer not null,")
1806 _T("perftab_settings $SQL:TEXT null,")
1807 _T("PRIMARY KEY(item_id))")));
1808
1809 CHK_EXEC(CreateTable(_T("CREATE TABLE dc_table_columns (")
1810 _T("table_id integer not null,")
1811 _T("column_name varchar(63) not null,")
1812 _T("snmp_oid varchar(1023) null,")
1813 _T("data_type integer not null,")
1814 _T("transformation_script $SQL:TEXT null,")
1815 _T("PRIMARY KEY(table_id,column_name))")));
1816
1817 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='248' WHERE var_name='SchemaVersion'")));
1818 return TRUE;
1819}
1820
480e036b
VK
1821/**
1822 * Upgrade from V246 to V247
1823 */
ff392ecf
VK
1824static BOOL H_UpgradeFromV246(int currVersion, int newVersion)
1825{
1826 static TCHAR insertQuery[] = _T("INSERT INTO object_custom_attributes (object_id,attr_name,attr_value) VALUES (?,?,?)");
1827
480e036b 1828 CHK_EXEC(SetColumnNullable(_T("object_custom_attributes"), _T("attr_value")));
ff392ecf
VK
1829
1830 // Convert strings in object_custom_attributes table
1831 DB_RESULT hResult = SQLSelect(_T("SELECT object_id,attr_name,attr_value FROM object_custom_attributes"));
1832 if (hResult != NULL)
1833 {
1834 if (SQLQuery(_T("DELETE FROM object_custom_attributes")))
1835 {
1836 TCHAR errorText[DBDRV_MAX_ERROR_TEXT];
1837 DB_STATEMENT hStmt = DBPrepareEx(g_hCoreDB, insertQuery, errorText);
1838 if (hStmt != NULL)
1839 {
1840 TCHAR name[128], *value;
1841 int count = DBGetNumRows(hResult);
1842 for(int i = 0; i < count; i++)
1843 {
967893bb 1844 UINT32 id = DBGetFieldULong(hResult, i, 0);
ff392ecf
VK
1845 DBGetField(hResult, i, 1, name, 128);
1846 DecodeSQLString(name);
1847 value = DBGetField(hResult, i, 2, NULL, 0);
1848 DecodeSQLString(value);
1849
1850 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, id);
1851 DBBind(hStmt, 2, DB_SQLTYPE_VARCHAR, name, DB_BIND_STATIC);
1852 DBBind(hStmt, 3, DB_SQLTYPE_VARCHAR, value, DB_BIND_DYNAMIC);
1853 if (g_bTrace)
1854 ShowQuery(insertQuery);
1855 if (!DBExecuteEx(hStmt, errorText))
1856 {
1857 WriteToTerminalEx(_T("SQL query failed (%s):\n\x1b[33;1m%s\x1b[0m\n"), errorText, insertQuery);
1858 if (!g_bIgnoreErrors)
1859 {
1860 DBFreeStatement(hStmt);
1861 DBFreeResult(hResult);
1862 return FALSE;
1863 }
1864 }
1865 }
1866 DBFreeStatement(hStmt);
1867 }
1868 else
1869 {
1870 WriteToTerminalEx(_T("SQL query failed (%s):\n\x1b[33;1m%s\x1b[0m\n"), errorText, insertQuery);
1871 if (!g_bIgnoreErrors)
1872 {
1873 DBFreeResult(hResult);
1874 return FALSE;
1875 }
1876 }
1877 }
1878 else
1879 {
1880 if (!g_bIgnoreErrors)
1881 {
1882 DBFreeResult(hResult);
1883 return FALSE;
1884 }
1885 }
1886
1887 DBFreeResult(hResult);
1888 }
1889 else
1890 {
1891 if (!g_bIgnoreErrors)
1892 return FALSE;
1893 }
1894
1895 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_ocattr_oid ON object_custom_attributes(object_id)")));
1896 CHK_EXEC(CreateConfigParam(_T("AlarmHistoryRetentionTime"), _T("180"), 1, 0));
1897
1898 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='247' WHERE var_name='SchemaVersion'")));
1899 return TRUE;
1900}
1901
d6bf58f9
VK
1902/**
1903 * Upgrade from V245 to V246
1904 */
98cd01bb
VK
1905static BOOL H_UpgradeFromV245(int currVersion, int newVersion)
1906{
6f33021d 1907 static TCHAR batch[] =
98cd01bb
VK
1908 _T("ALTER TABLE snmp_trap_pmap ADD flags integer\n")
1909 _T("UPDATE snmp_trap_pmap SET flags=0\n")
1910 _T("<END>");
1911
1912 CHK_EXEC(SQLBatch(batch));
1913
480e036b 1914 CHK_EXEC(SetColumnNullable(_T("snmp_trap_pmap"), _T("description")));
d6bf58f9 1915 CHK_EXEC(ConvertStrings(_T("snmp_trap_pmap"), _T("trap_id"), _T("parameter"), _T("description"), false));
6f33021d 1916
480e036b 1917 CHK_EXEC(SetColumnNullable(_T("cluster_resources"), _T("resource_name")));
d6bf58f9 1918 CHK_EXEC(ConvertStrings(_T("cluster_resources"), _T("cluster_id"), _T("resource_id"), _T("resource_name"), false));
6f33021d 1919
98cd01bb
VK
1920 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='246' WHERE var_name='SchemaVersion'")));
1921 return TRUE;
1922}
1923
d6bf58f9
VK
1924/**
1925 * Upgrade from V244 to V245
1926 */
4866d57b
VK
1927static BOOL H_UpgradeFromV244(int currVersion, int newVersion)
1928{
6f33021d 1929 static TCHAR batch[] =
4866d57b
VK
1930 _T("ALTER TABLE nodes ADD runtime_flags integer\n")
1931 _T("UPDATE nodes SET runtime_flags=0\n")
1932 _T("<END>");
1933
1934 CHK_EXEC(SQLBatch(batch));
1935
480e036b
VK
1936 CHK_EXEC(SetColumnNullable(_T("actions"), _T("rcpt_addr")));
1937 CHK_EXEC(SetColumnNullable(_T("actions"), _T("email_subject")));
1938 CHK_EXEC(SetColumnNullable(_T("actions"), _T("action_data")));
4866d57b
VK
1939
1940 CHK_EXEC(ConvertStrings(_T("actions"), _T("action_id"), _T("rcpt_addr")));
1941 CHK_EXEC(ConvertStrings(_T("actions"), _T("action_id"), _T("email_subject")));
1942 CHK_EXEC(ConvertStrings(_T("actions"), _T("action_id"), _T("action_data")));
6f33021d 1943
4866d57b
VK
1944 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='245' WHERE var_name='SchemaVersion'")));
1945 return TRUE;
1946}
1947
1948
aa16f82b
VK
1949//
1950// Upgrade from V243 to V244
1951//
1952
1953static BOOL H_UpgradeFromV243(int currVersion, int newVersion)
1954{
6f33021d 1955 static TCHAR batch[] =
aa16f82b
VK
1956 _T("ALTER TABLE interfaces ADD dot1x_pae_state integer\n")
1957 _T("ALTER TABLE interfaces ADD dot1x_backend_state integer\n")
1958 _T("UPDATE interfaces SET dot1x_pae_state=0,dot1x_backend_state=0\n")
1959 _T("<END>");
1960
1961 CHK_EXEC(SQLBatch(batch));
1962
1963 CHK_EXEC(CreateEventTemplate(EVENT_8021X_PAE_STATE_CHANGED, _T("SYS_8021X_PAE_STATE_CHANGED"),
6f33021d 1964 EVENT_SEVERITY_NORMAL, 1, _T("Port %6 PAE state changed from %4 to %2"),
aa16f82b
VK
1965 _T("Generated when switch port PAE state changed.\r\nParameters:\r\n")
1966 _T(" 1) New PAE state code\r\n")
1967 _T(" 2) New PAE state as text\r\n")
1968 _T(" 3) Old PAE state code\r\n")
1969 _T(" 4) Old PAE state as text\r\n")
1970 _T(" 5) Interface index\r\n")
1971 _T(" 6) Interface name")));
1972
1973 CHK_EXEC(CreateEventTemplate(EVENT_8021X_BACKEND_STATE_CHANGED, _T("SYS_8021X_BACKEND_STATE_CHANGED"),
6f33021d 1974 EVENT_SEVERITY_NORMAL, 1, _T("Port %6 backend authentication state changed from %4 to %2"),
aa16f82b
VK
1975 _T("Generated when switch port backend authentication state changed.\r\nParameters:\r\n")
1976 _T(" 1) New backend state code\r\n")
1977 _T(" 2) New backend state as text\r\n")
1978 _T(" 3) Old backend state code\r\n")
1979 _T(" 4) Old backend state as text\r\n")
1980 _T(" 5) Interface index\r\n")
1981 _T(" 6) Interface name")));
1982
1983 CHK_EXEC(CreateEventTemplate(EVENT_8021X_PAE_FORCE_UNAUTH, _T("SYS_8021X_PAE_FORCE_UNAUTH"),
6f33021d 1984 EVENT_SEVERITY_MAJOR, 1, _T("Port %2 switched to force unauthorize state"),
aa16f82b
VK
1985 _T("Generated when switch port PAE state changed to FORCE UNAUTHORIZE.\r\nParameters:\r\n")
1986 _T(" 1) Interface index\r\n")
1987 _T(" 2) Interface name")));
1988
1989 CHK_EXEC(CreateEventTemplate(EVENT_8021X_AUTH_FAILED, _T("SYS_8021X_AUTH_FAILED"),
6f33021d 1990 EVENT_SEVERITY_MAJOR, 1, _T("802.1x authentication failed on port %2"),
aa16f82b
VK
1991 _T("Generated when switch port backend authentication state changed to FAIL.\r\nParameters:\r\n")
1992 _T(" 1) Interface index\r\n")
1993 _T(" 2) Interface name")));
1994
1995 CHK_EXEC(CreateEventTemplate(EVENT_8021X_AUTH_TIMEOUT, _T("SYS_8021X_AUTH_TIMEOUT"),
6f33021d 1996 EVENT_SEVERITY_MAJOR, 1, _T("802.1x authentication time out on port %2"),
aa16f82b
VK
1997 _T("Generated when switch port backend authentication state changed to TIMEOUT.\r\nParameters:\r\n")
1998 _T(" 1) Interface index\r\n")
1999 _T(" 2) Interface name")));
2000
2001 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='244' WHERE var_name='SchemaVersion'")));
2002 return TRUE;
2003}
2004
2005
e320f8ce
VK
2006//
2007// Upgrade from V242 to V243
2008//
2009
2010static BOOL H_UpgradeFromV242(int currVersion, int newVersion)
2011{
6f33021d 2012 static TCHAR batch[] =
242e9c7f
VK
2013 _T("ALTER TABLE items ADD snmp_raw_value_type integer\n")
2014 _T("UPDATE items SET snmp_raw_value_type=0\n")
e320f8ce
VK
2015 _T("ALTER TABLE items ADD flags integer\n")
2016 _T("UPDATE items SET flags=adv_schedule+(all_thresholds*2)\n")
2017 _T("ALTER TABLE items DROP COLUMN adv_schedule\n")
2018 _T("ALTER TABLE items DROP COLUMN all_thresholds\n")
e320f8ce
VK
2019 _T("<END>");
2020
2021 CHK_EXEC(SQLBatch(batch));
2022 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='243' WHERE var_name='SchemaVersion'")));
2023 return TRUE;
2024}
2025
2026
f5e80875
VK
2027//
2028// Upgrade from V241 to V242
2029//
2030
2031static BOOL H_UpgradeFromV241(int currVersion, int newVersion)
2032{
6f33021d 2033 static TCHAR batch[] =
f5e80875
VK
2034 _T("DROP TABLE business_service_templates\n")
2035 _T("ALTER TABLE dashboards ADD options integer\n")
2036 _T("UPDATE dashboards SET options=0\n")
2037 _T("<END>");
2038
2039 CHK_EXEC(SQLBatch(batch));
2040 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='242' WHERE var_name='SchemaVersion'")));
2041 return TRUE;
2042}
2043
2044
6ff21d27
VK
2045//
2046// Upgrade from V240 to V241
2047//
2048
2049static BOOL H_UpgradeFromV240(int currVersion, int newVersion)
2050{
6f33021d 2051 static TCHAR batch[] =
6ff21d27
VK
2052 _T("ALTER TABLE slm_checks ADD template_id integer\n")
2053 _T("ALTER TABLE slm_checks ADD current_ticket integer\n")
2054 _T("UPDATE slm_checks SET template_id=0,current_ticket=0\n")
2055 _T("<END>");
2056
2057 CHK_EXEC(SQLBatch(batch));
2058 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='241' WHERE var_name='SchemaVersion'")));
2059 return TRUE;
2060}
2061
2062
5fe19f9e
VK
2063//
2064// Upgrade from V239 to V240
2065//
2066
2067static BOOL H_UpgradeFromV239(int currVersion, int newVersion)
2068{
2069 CHK_EXEC(SQLQuery(_T("ALTER TABLE raw_dci_values ADD transformed_value varchar(255)")));
2070 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='240' WHERE var_name='SchemaVersion'")));
2071 return TRUE;
2072}
2073
2074
5a7d6a10
VK
2075//
2076// Upgrade from V238 to V239
2077//
2078
2079static BOOL H_UpgradeFromV238(int currVersion, int newVersion)
2080{
2081 CHK_EXEC(SQLQuery(
2082 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES ")
2083 _T("(56,'SYS_IP_ADDRESS_CHANGED',1,1,'Primary IP address changed from %2 to %1',")
2084 _T("'Generated when primary IP address changed (usually because of primary name change or DNS change).#0D#0A")
2085 _T("Parameters:#0D#0A 1) New IP address#0D#0A 2) Old IP address#0D#0A 3) Primary host name')")));
2086
2087 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='239' WHERE var_name='SchemaVersion'")));
2088 return TRUE;
2089}
2090
2091
34ccf87f
VK
2092//
2093// Upgrade from V232 to V238
2094//
2095
2096static BOOL H_UpgradeFromV232toV238(int currVersion, int newVersion)
2097{
2098 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_checks (")
2099 _T("id integer not null,")
2100 _T("type integer not null,")
2101 _T("content $SQL:TEXT null,")
2102 _T("threshold_id integer not null,")
2103 _T("reason varchar(255) null,")
2104 _T("is_template integer not null,")
2105 _T("PRIMARY KEY(id))")));
2106
2107 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_tickets (")
2108 _T("ticket_id integer not null,")
2109 _T("service_id integer not null,")
2110 _T("check_id integer not null,")
2111 _T("create_timestamp integer not null,")
2112 _T("close_timestamp integer not null,")
2113 _T("reason varchar(255) null,")
2114 _T("PRIMARY KEY(ticket_id))")));
2115
2116 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_service_history (")
2117 _T("record_id integer not null,")
2118 _T("service_id integer not null,")
2119 _T("change_timestamp integer not null,")
2120 _T("new_status integer not null,")
2121 _T("PRIMARY KEY(record_id))")));
2122
2123 CHK_EXEC(CreateTable(_T("CREATE TABLE report_results (")
2124 _T("report_id integer not null,")
2125 _T("generated integer not null,")
2126 _T("job_id integer not null,")
2127 _T("PRIMARY KEY(report_id,job_id))")));
2128
2129 CHK_EXEC(CreateTable(_T("CREATE TABLE reports (")
2130 _T("id integer not null,")
2131 _T("definition $SQL:TEXT null,")
2132 _T("PRIMARY KEY(id))")));
2133
2134 CHK_EXEC(CreateTable(_T("CREATE TABLE job_history (")
2135 _T("id integer not null,")
2136 _T("time_created integer not null,")
2137 _T("time_started integer not null,")
2138 _T("time_finished integer not null,")
2139 _T("job_type varchar(127) null,")
2140 _T("description varchar(255) null,")
2141 _T("additional_info varchar(255) null,")
2142 _T("node_id integer not null,")
2143 _T("user_id integer not null,")
2144 _T("status integer not null,")
2145 _T("failure_message varchar(255) null,")
2146 _T("PRIMARY KEY(id))")));
2147
2148 CHK_EXEC(CreateTable(_T("CREATE TABLE business_services (")
2149 _T("service_id integer not null,")
2150 _T("PRIMARY KEY(service_id))")));
2151
2152 CHK_EXEC(CreateTable(_T("CREATE TABLE business_service_templates (")
2153 _T("service_id integer not null,")
2154 _T("template_id integer not null,")
2155 _T("PRIMARY KEY(service_id,template_id))")));
2156
2157 CHK_EXEC(CreateTable(_T("CREATE TABLE node_links (")
2158 _T("nodelink_id integer not null,")
2159 _T("node_id integer not null,")
2160 _T("PRIMARY KEY(nodelink_id))")));
2161
2162 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_agreements (")
2163 _T("agreement_id integer not null,")
2164 _T("service_id integer not null,")
2165 _T("org_id integer not null,")
2166 _T("uptime varchar(63) not null,")
2167 _T("period integer not null,")
2168 _T("start_date integer not null,")
2169 _T("notes varchar(255),")
2170 _T("PRIMARY KEY(agreement_id))")));
2171
2172 CHK_EXEC(CreateTable(_T("CREATE TABLE organizations (")
2173 _T("id integer not null,")
2174 _T("parent_id integer not null,")
2175 _T("org_type integer not null,")
2176 _T("name varchar(63) not null,")
2177 _T("description varchar(255),")
2178 _T("manager integer not null,")
2179 _T("PRIMARY KEY(id))")));
2180
2181 CHK_EXEC(CreateTable(_T("CREATE TABLE persons (")
2182 _T("id integer not null,")
2183 _T("org_id integer not null,")
2184 _T("first_name varchar(63),")
2185 _T("last_name varchar(63),")
2186 _T("title varchar(255),")
2187 _T("status integer not null,")
2188 _T("PRIMARY KEY(id))")));
2189
2190 CHK_EXEC(CreateConfigParam(_T("JobHistoryRetentionTime"), _T("90"), 1, 0));
2191
2192 CHK_EXEC(SQLQuery(_T("UPDATE event_cfg SET description=")
2193 _T("'Generated when threshold check is rearmed for specific data collection item.#0D#0A")
2194 _T("Parameters:#0D#0A")
2195 _T(" 1) Parameter name#0D#0A")
2196 _T(" 2) Item description#0D#0A")
2197 _T(" 3) Data collection item ID#0D#0A")
2198 _T(" 4) Instance#0D#0A")
2199 _T(" 5) Threshold value#0D#0A")
2200 _T(" 6) Actual value' WHERE event_code=18")));
2201
2202 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='238' WHERE var_name='SchemaVersion'")));
2203 return TRUE;
2204}
2205
2206
9c529287
VK
2207//
2208// Upgrade from V237 to V238
2209//
2210
2211static BOOL H_UpgradeFromV237(int currVersion, int newVersion)
2212{
6f33021d 2213 static TCHAR batch[] =
9c529287
VK
2214 _T("DROP TABLE slm_check_templates\n")
2215 _T("DROP TABLE node_link_checks\n")
2216 _T("DROP TABLE slm_checks\n")
2217 _T("DROP TABLE slm_tickets\n")
2218 _T("<END>");
2219
2220 CHK_EXEC(SQLBatch(batch));
2221
2222 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_checks (")
2223 _T("id integer not null,")
2224 _T("type integer not null,")
2225 _T("content $SQL:TEXT null,")
2226 _T("threshold_id integer not null,")
2227 _T("reason varchar(255) null,")
2228 _T("is_template integer not null,")
2229 _T("PRIMARY KEY(id))")));
2230
2231 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_tickets (")
2232 _T("ticket_id integer not null,")
2233 _T("service_id integer not null,")
2234 _T("check_id integer not null,")
2235 _T("create_timestamp integer not null,")
2236 _T("close_timestamp integer not null,")
2237 _T("reason varchar(255) null,")
2238 _T("PRIMARY KEY(ticket_id))")));
2239
2240 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_service_history (")
2241 _T("record_id integer not null,")
2242 _T("service_id integer not null,")
2243 _T("change_timestamp integer not null,")
2244 _T("new_status integer not null,")
2245 _T("PRIMARY KEY(record_id))")));
2246
2247 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='238' WHERE var_name='SchemaVersion'")));
2248 return TRUE;
2249}
2250
2251
f5c9fdc5
VK
2252//
2253// Upgrade from V236 to V237
2254//
2255
2256static BOOL H_UpgradeFromV236(int currVersion, int newVersion)
2257{
6f33021d 2258 static TCHAR batch[] =
f5c9fdc5
VK
2259 _T("ALTER TABLE business_services DROP COLUMN name\n")
2260 _T("ALTER TABLE business_services DROP COLUMN parent_id\n")
2261 _T("ALTER TABLE business_services DROP COLUMN status\n")
2262 _T("ALTER TABLE slm_checks DROP COLUMN name\n")
2263 _T("<END>");
2264
2265 CHK_EXEC(SQLBatch(batch));
2266
2267 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='237' WHERE var_name='SchemaVersion'")));
2268 return TRUE;
2269}
2270
2271
5418326b
AK
2272//
2273// Upgrade from V235 to V236
2274//
2275
2276static BOOL H_UpgradeFromV235(int currVersion, int newVersion)
2277{
2278 CHK_EXEC(CreateTable(_T("CREATE TABLE report_results (")
2279 _T("report_id integer not null,")
2280 _T("generated integer not null,")
2281 _T("job_id integer not null,")
2282 _T("PRIMARY KEY(report_id,job_id))")));
2283
2284 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='236' WHERE var_name='SchemaVersion'")));
2285 return TRUE;
2286}
2287
2288
845b8121
VK
2289//
2290// Upgrade from V234 to V235
2291//
2292
2293static BOOL H_UpgradeFromV234(int currVersion, int newVersion)
2294{
2295 CHK_EXEC(CreateTable(_T("CREATE TABLE reports (")
2296 _T("id integer not null,")
2297 _T("definition $SQL:TEXT null,")
2298 _T("PRIMARY KEY(id))")));
2299
845b8121
VK
2300 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='235' WHERE var_name='SchemaVersion'")));
2301 return TRUE;
2302}
2303
2304
878b4261
VK
2305//
2306// Upgrade from V233 to V234
2307//
2308
2309static BOOL H_UpgradeFromV233(int currVersion, int newVersion)
2310{
2311 CHK_EXEC(CreateTable(_T("CREATE TABLE job_history (")
2312 _T("id integer not null,")
2313 _T("time_created integer not null,")
2314 _T("time_started integer not null,")
2315 _T("time_finished integer not null,")
2316 _T("job_type varchar(127) null,")
2317 _T("description varchar(255) null,")
24dc5346 2318 _T("additional_info varchar(255) null,")
878b4261
VK
2319 _T("node_id integer not null,")
2320 _T("user_id integer not null,")
2321 _T("status integer not null,")
2322 _T("failure_message varchar(255) null,")
2323 _T("PRIMARY KEY(id))")));
2324
2325 CHK_EXEC(CreateConfigParam(_T("JobHistoryRetentionTime"), _T("90"), 1, 0));
2326
2327 CHK_EXEC(SQLQuery(_T("UPDATE event_cfg SET description=")
2328 _T("'Generated when threshold check is rearmed for specific data collection item.#0D#0A")
2329 _T("Parameters:#0D#0A")
2330 _T(" 1) Parameter name#0D#0A")
2331 _T(" 2) Item description#0D#0A")
2332 _T(" 3) Data collection item ID#0D#0A")
2333 _T(" 4) Instance#0D#0A")
2334 _T(" 5) Threshold value#0D#0A")
2335 _T(" 6) Actual value' WHERE event_code=18")));
2336
2337 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='234' WHERE var_name='SchemaVersion'")));
2338 return TRUE;
2339}
2340
2341
128681c8
VK
2342//
2343// Upgrade from V232 to V233
2344//
2345
2346static BOOL H_UpgradeFromV232(int currVersion, int newVersion)
2347{
2348 CHK_EXEC(CreateTable(_T("CREATE TABLE business_services (")
2349 _T("service_id integer not null,")
2350 _T("name varchar(63) not null,")
2498594e
VK
2351 _T("parent_id integer not null,")
2352 _T("status integer not null,")
128681c8
VK
2353 _T("PRIMARY KEY(service_id))")));
2354
128681c8
VK
2355 CHK_EXEC(CreateTable(_T("CREATE TABLE business_service_templates (")
2356 _T("service_id integer not null,")
2357 _T("template_id integer not null,")
2358 _T("PRIMARY KEY(service_id,template_id))")));
2359
2360 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_checks (")
2361 _T("check_id integer not null,")
2362 _T("name varchar(63) not null,")
2498594e 2363 _T("type integer not null,")
128681c8 2364 _T("content $SQL:TEXT,")
2498594e 2365 _T("threshold_id integer not null,")
128681c8
VK
2366 _T("state integer not null,")
2367 _T("reason varchar(255) not null,")
2368 _T("PRIMARY KEY(check_id))")));
2369
2370 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_check_templates (")
2371 _T("id integer not null,")
2372 _T("name varchar(63) not null,")
2498594e 2373 _T("type integer not null,")
128681c8 2374 _T("content $SQL:TEXT,")
2498594e 2375 _T("threshold_id integer not null,")
128681c8
VK
2376 _T("PRIMARY KEY(id))")));
2377
2378 CHK_EXEC(CreateTable(_T("CREATE TABLE node_links (")
2379 _T("nodelink_id integer not null,")
2380 _T("node_id integer not null,")
2381 _T("PRIMARY KEY(nodelink_id))")));
2382
2383 CHK_EXEC(CreateTable(_T("CREATE TABLE node_link_checks (")
2384 _T("nodelink_id integer not null,")
2385 _T("check_id integer not null,")
2386 _T("PRIMARY KEY(nodelink_id,check_id))")));
2387
2388 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_agreements (")
2389 _T("agreement_id integer not null,")
2390 _T("service_id integer not null,")
2391 _T("org_id integer not null,")
2392 _T("uptime varchar(63) not null,")
2393 _T("period integer not null,")
2394 _T("start_date integer not null,")
2395 _T("notes varchar(255),")
2396 _T("PRIMARY KEY(agreement_id))")));
2397
2398 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_tickets (")
2399 _T("ticket_id integer not null,")
2400 _T("service_id integer not null,")
2401 _T("create_timestamp integer not null,")
2402 _T("close_timestamp integer not null,")
2403 _T("reason varchar(255) not null,")
2404 _T("PRIMARY KEY(ticket_id))")));
2405
2406 CHK_EXEC(CreateTable(_T("CREATE TABLE organizations (")
2407 _T("id integer not null,")
2408 _T("parent_id integer not null,")
2409 _T("org_type integer not null,")
2410 _T("name varchar(63) not null,")
2411 _T("description varchar(255),")
2412 _T("manager integer not null,")
2413 _T("PRIMARY KEY(id))")));
2414
2415 CHK_EXEC(CreateTable(_T("CREATE TABLE persons (")
2416 _T("id integer not null,")
2417 _T("org_id integer not null,")
2418 _T("first_name varchar(63),")
2419 _T("last_name varchar(63),")
2420 _T("title varchar(255),")
2421 _T("status integer not null,")
2422 _T("PRIMARY KEY(id))")));
2423
2424 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='233' WHERE var_name='SchemaVersion'")));
2425 return TRUE;
2426}
2427
2428
8f245200
VK
2429//
2430// Upgrade from V231 to V232
2431//
2432
2433static BOOL H_UpgradeFromV231(int currVersion, int newVersion)
2434{
6f33021d 2435 static TCHAR batch[] =
8f245200
VK
2436 _T("ALTER TABLE object_properties ADD submap_id integer\n")
2437 _T("UPDATE object_properties SET submap_id=0\n")
2438 _T("DROP TABLE maps\n")
2439 _T("DROP TABLE map_access_lists\n")
2440 _T("DROP TABLE submaps\n")
2441 _T("DROP TABLE submap_object_positions\n")
2442 _T("DROP TABLE submap_links\n")
2443 _T("<END>");
2444
2445 CHK_EXEC(SQLBatch(batch));
2446
2447 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='232' WHERE var_name='SchemaVersion'")));
2448 return TRUE;
2449}
2450
2451
3eab63f2
VK
2452//
2453// Upgrade from V230 to V231
2454//
2455
2456static BOOL H_UpgradeFromV230(int currVersion, int newVersion)
2457{
6f33021d 2458 static TCHAR batch[] =
3eab63f2
VK
2459 _T("ALTER TABLE nodes ADD bridge_base_addr varchar(15)\n")
2460 _T("UPDATE nodes SET bridge_base_addr='000000000000'\n")
2461 _T("<END>");
2462
2463 CHK_EXEC(SQLBatch(batch));
2464
2465 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='231' WHERE var_name='SchemaVersion'")));
2466 return TRUE;
2467}
2468
2469
fceea457
VK
2470//
2471// Upgrade from V229 to V230
2472//
2473
2474static BOOL H_UpgradeFromV229(int currVersion, int newVersion)
2475{
6f33021d 2476 static TCHAR batch1[] =
1a74dc37
VK
2477 _T("ALTER TABLE network_maps ADD bg_latitude varchar(20)\n")
2478 _T("ALTER TABLE network_maps ADD bg_longitude varchar(20)\n")
2479 _T("ALTER TABLE network_maps ADD bg_zoom integer\n")
fceea457
VK
2480 _T("ALTER TABLE dashboard_elements ADD layout_data $SQL:TEXT\n")
2481 _T("<END>");
2482
2483 CHK_EXEC(SQLBatch(batch1));
2484
2485 DB_RESULT hResult = SQLSelect(_T("SELECT dashboard_id,element_id,horizontal_span,vertical_span,horizontal_alignment,vertical_alignment FROM dashboard_elements"));
2486 if (hResult != NULL)
2487 {
2488 TCHAR query[1024], xml[1024];
2489
2490 int count = DBGetNumRows(hResult);
2491 for(int i = 0; i < count; i++)
2492 {
2493 _sntprintf(xml, 1024, _T("<layout><horizontalSpan>%d</horizontalSpan><verticalSpan>%d</verticalSpan><horizontalAlignment>%d</horizontalAlignment><verticalAlignment>%d</verticalAlignment></layout>"),
2494 (int)DBGetFieldLong(hResult, i, 2), (int)DBGetFieldLong(hResult, i, 3),
2495 (int)DBGetFieldLong(hResult, i, 4), (int)DBGetFieldLong(hResult, i, 5));
2496 _sntprintf(query, 1024, _T("UPDATE dashboard_elements SET layout_data=%s WHERE dashboard_id=%d AND element_id=%d"),
2497 (const TCHAR *)DBPrepareString(g_hCoreDB, xml), (int)DBGetFieldLong(hResult, i, 0), (int)DBGetFieldLong(hResult, i, 1));
2498 CHK_EXEC(SQLQuery(query));
2499 }
2500 DBFreeResult(hResult);
2501 }
2502 else
2503 {
2504 if (!g_bIgnoreErrors)
2505 return FALSE;
2506 }
2507
6f33021d 2508 static TCHAR batch2[] =
fceea457
VK
2509 _T("ALTER TABLE dashboard_elements DROP COLUMN horizontal_span\n")
2510 _T("ALTER TABLE dashboard_elements DROP COLUMN vertical_span\n")
2511 _T("ALTER TABLE dashboard_elements DROP COLUMN horizontal_alignment\n")
2512 _T("ALTER TABLE dashboard_elements DROP COLUMN vertical_alignment\n")
2513 _T("<END>");
2514
2515 CHK_EXEC(SQLBatch(batch2));
2516
2517 CreateConfigParam(_T("TileServerURL"), _T("http://tile.openstreetmap.org/"), 1, 0);
2518
2519 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='230' WHERE var_name='SchemaVersion'")));
2520 return TRUE;
2521}
2522
2523
926e8ce7
VK
2524//
2525// Upgrade from V228 to V229
2526//
2527
2528static BOOL H_UpgradeFromV228(int currVersion, int newVersion)
2529{
2530 CHK_EXEC(CreateTable(_T("CREATE TABLE dashboards (")
2531 _T(" id integer not null,")
2532 _T(" num_columns integer not null,")
2533 _T(" PRIMARY KEY(id))")));
2534
2535 CHK_EXEC(CreateTable(_T("CREATE TABLE dashboard_elements (")
2536 _T(" dashboard_id integer not null,")
2537 _T(" element_id integer not null,")
2538 _T(" element_type integer not null,")
2539 _T(" element_data $SQL:TEXT null,")
2540 _T(" horizontal_span integer not null,")
2541 _T(" vertical_span integer not null,")
2542 _T(" horizontal_alignment integer not null,")
2543 _T(" vertical_alignment integer not null,")
2544 _T(" PRIMARY KEY(dashboard_id,element_id))")));
2545
2546 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='229' WHERE var_name='SchemaVersion'")));
2547 return TRUE;
2548}
2549
badf9a95
VK
2550/**
2551 * Upgrade from V227 to V228
2552 */
7a41a06e
VK
2553static BOOL H_UpgradeFromV227(int currVersion, int newVersion)
2554{
2555 CHK_EXEC(SQLQuery(_T("DROP TABLE web_maps")));
2556 CHK_EXEC(MigrateMaps());
2557 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='228' WHERE var_name='SchemaVersion'")));
2558 return TRUE;
2559}
2560
badf9a95
VK
2561/**
2562 * Upgrade from V226 to V227
2563 */
89135050
VK
2564static BOOL H_UpgradeFromV226(int currVersion, int newVersion)
2565{
6f33021d 2566 static TCHAR batch[] =
89135050
VK
2567 _T("ALTER TABLE clusters ADD zone_guid integer\n")
2568 _T("UPDATE clusters SET zone_guid=0\n")
2569 _T("<END>");
2570
2571 CHK_EXEC(SQLBatch(batch));
2572
2573 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='227' WHERE var_name='SchemaVersion'")));
2574 return TRUE;
2575}
2576
2577
4c16cdc7
VK
2578//
2579// Upgrade from V225 to V226
2580//
2581
2582static BOOL H_UpgradeFromV225(int currVersion, int newVersion)
2583{
6f33021d 2584 static TCHAR batch[] =
4c16cdc7
VK
2585 _T("ALTER TABLE interfaces ADD flags integer\n")
2586 _T("UPDATE interfaces SET flags=0\n")
2587 _T("UPDATE interfaces SET flags=1 WHERE synthetic_mask<>0\n")
2588 _T("ALTER TABLE interfaces DROP COLUMN synthetic_mask\n")
2589 _T("<END>");
2590
2591 CHK_EXEC(SQLBatch(batch));
2592
2593 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='226' WHERE var_name='SchemaVersion'")));
2594 return TRUE;
2595}
2596
2597
478d4ff4
VK
2598//
2599// Upgrade from V224 to V225
2600//
2601
2602static BOOL H_UpgradeFromV224(int currVersion, int newVersion)
2603{
6f33021d 2604 static TCHAR batch[] =
478d4ff4
VK
2605 _T("ALTER TABLE interfaces ADD description varchar(255)\n")
2606 _T("UPDATE interfaces SET description=''\n")
2607 _T("<END>");
2608
2609 CHK_EXEC(SQLBatch(batch));
2610
2611 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='225' WHERE var_name='SchemaVersion'")));
2612 return TRUE;
2613}
2614
badf9a95
VK
2615/**
2616 * Upgrade from V223 to V224
2617 */
52c31148
VK
2618static BOOL H_UpgradeFromV223(int currVersion, int newVersion)
2619{
6f33021d 2620 static TCHAR batch[] =
52c31148
VK
2621 _T("DROP TABLE zone_ip_addr_list\n")
2622 _T("ALTER TABLE zones DROP COLUMN zone_type\n")
2623 _T("ALTER TABLE zones DROP COLUMN controller_ip\n")
2624 _T("ALTER TABLE zones ADD agent_proxy integer\n")
2625 _T("ALTER TABLE zones ADD snmp_proxy integer\n")
2626 _T("ALTER TABLE zones ADD icmp_proxy integer\n")
2627 _T("UPDATE zones SET agent_proxy=0,snmp_proxy=0,icmp_proxy=0\n")
2628 _T("<END>");
2629
2630 CHK_EXEC(SQLBatch(batch));
2631
2632 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='224' WHERE var_name='SchemaVersion'")));
2633 return TRUE;
2634}
2635
badf9a95
VK
2636/**
2637 * Upgrade from V222 to V223
2638 */
5ad2167d
VK
2639static BOOL H_UpgradeFromV222(int currVersion, int newVersion)
2640{
6f33021d 2641 static TCHAR batch[] =
5ad2167d
VK
2642 _T("DROP TABLE oid_to_type\n")
2643 _T("ALTER TABLE nodes DROP COLUMN node_type\n")
2644 _T("ALTER TABLE nodes ADD primary_name varchar(255)\n")
2645 _T("UPDATE nodes SET primary_name=primary_ip\n")
2646 _T("<END>");
2647
2648 CHK_EXEC(SQLBatch(batch));
2649
2650 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='223' WHERE var_name='SchemaVersion'")));
2651 return TRUE;
2652}
2653
2654
465b3f2d 2655//
f25b0d12
VK
2656// Upgrade from V221 to V222
2657//
2658
2659static BOOL H_UpgradeFromV221(int currVersion, int newVersion)
2660{
6f33021d 2661 static TCHAR batch[] =
f25b0d12
VK
2662 _T("ALTER TABLE object_properties ADD image varchar(36)\n")
2663 _T("UPDATE object_properties SET image='00000000-0000-0000-0000-000000000000'\n")
2664 _T("<END>");
2665
2666 CHK_EXEC(SQLBatch(batch));
2667
2668 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='222' WHERE var_name='SchemaVersion'")));
2669 return TRUE;
2670}
2671
2672
2673//
2674// Upgrade from V220 to V221
465b3f2d
VK
2675//
2676
2677static BOOL H_UpgradeFromV220(int currVersion, int newVersion)
2678{
6f33021d 2679 static TCHAR batch[] =
465b3f2d
VK
2680 _T("ALTER TABLE network_maps DROP COLUMN background\n")
2681 _T("ALTER TABLE network_maps ADD background varchar(36)\n")
2682 _T("<END>");
2683
2684 CHK_EXEC(SQLBatch(batch));
2685
2686 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='221' WHERE var_name='SchemaVersion'")));
2687 return TRUE;
2688}
2689
2690
d74c80ea
VK
2691//
2692// Upgrade from V219 to V220
2693//
2694
2695static BOOL H_UpgradeFromV219(int currVersion, int newVersion)
2696{
6f33021d 2697 static TCHAR batch[] =
d74c80ea
VK
2698 _T("ALTER TABLE interfaces ADD bridge_port integer\n")
2699 _T("ALTER TABLE interfaces ADD phy_slot integer\n")
2700 _T("ALTER TABLE interfaces ADD phy_port integer\n")
2701 _T("ALTER TABLE interfaces ADD peer_node_id integer\n")
2702 _T("ALTER TABLE interfaces ADD peer_if_id integer\n")
2703 _T("UPDATE interfaces SET bridge_port=0,phy_slot=0,phy_port=0,peer_node_id=0,peer_if_id=0\n")
2704 _T("ALTER TABLE nodes ADD snmp_sys_name varchar(127)\n")
2705 _T("UPDATE nodes SET snmp_sys_name=''\n")
2706 _T("<END>");
2707
2708 CHK_EXEC(SQLBatch(batch));
2709
2710 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='220' WHERE var_name='SchemaVersion'")));
2711 return TRUE;
2712}
2713
2714
e6b9439a
AK
2715//
2716// Upgrade from V218 to V219
2717//
2718
2719static BOOL H_UpgradeFromV218(int currVersion, int newVersion)
2720{
2721 CHK_EXEC(CreateTable(_T("CREATE TABLE images (")
9cd5201a
AK
2722 _T(" guid varchar(36) not null,")
2723 _T(" mimetype varchar(64) not null,")
2724 _T(" name varchar(255) not null,")
e6b9439a
AK
2725 _T(" category varchar(255) not null,")
2726 _T(" protected integer default 0,")
2727 _T(" ")
9cd5201a
AK
2728 _T(" PRIMARY KEY(guid),")
2729 _T(" UNIQUE(name, category))")));
2730
2731 static TCHAR batch[] =
2732 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2733 _T("('1ddb76a3-a05f-4a42-acda-22021768feaf', 'image/png', 'ATM', 'Network Objects', 1)\n")
9cd5201a 2734 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2735 _T("('b314cf44-b2aa-478e-b23a-73bc5bb9a624', 'image/png', 'HSM', 'Network Objects', 1)\n")
9cd5201a 2736 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2737 _T("('904e7291-ee3f-41b7-8132-2bd29288ecc8', 'image/png', 'Node', 'Network Objects', 1)\n")
9cd5201a 2738 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2739 _T("('f5214d16-1ab1-4577-bb21-063cfd45d7af', 'image/png', 'Printer', 'Network Objects', 1)\n")
9cd5201a 2740 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2741 _T("('bacde727-b183-4e6c-8dca-ab024c88b999', 'image/png', 'Router', 'Network Objects', 1)\n")
9cd5201a 2742 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2743 _T("('ba6ab507-f62d-4b8f-824c-ca9d46f22375', 'image/png', 'Server', 'Network Objects', 1)\n")
9cd5201a 2744 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2745 _T("('092e4b35-4e7c-42df-b9b7-d5805bfac64e', 'image/png', 'Service', 'Network Objects', 1)\n")
9cd5201a 2746 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2747 _T("('f9105c54-8dcf-483a-b387-b4587dfd3cba', 'image/png', 'Switch', 'Network Objects', 1)\n")
9cd5201a 2748 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2749 _T("('7cd999e9-fbe0-45c3-a695-f84523b3a50c', 'image/png', 'Unknown', 'Network Objects', 1)\n")
9cd5201a
AK
2750 _T("<END>");
2751
2752 CHK_EXEC(SQLBatch(batch));
e6b9439a
AK
2753
2754 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='219' WHERE var_name='SchemaVersion'")));
2755 return TRUE;
2756}
2757
480e036b
VK
2758/**
2759 * Upgrade from V217 to V218
2760 */
4fe87cdc
VK
2761static BOOL H_UpgradeFromV217(int currVersion, int newVersion)
2762{
480e036b 2763 CHK_EXEC(SetColumnNullable(_T("snmp_communities"), _T("community")));
4fe87cdc
VK
2764 CHK_EXEC(ConvertStrings(_T("snmp_communities"), _T("id"), _T("community")));
2765
2766 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='218' WHERE var_name='SchemaVersion'")));
2767 return TRUE;
2768}
2769
480e036b
VK
2770/**
2771 * Upgrade from V216 to V217
2772 */
65e2005b
VK
2773static BOOL H_UpgradeFromV216(int currVersion, int newVersion)
2774{
6f33021d 2775 static TCHAR batch[] =
65e2005b 2776 _T("ALTER TABLE nodes ADD snmp_port integer\n")
8cad4ebb 2777 _T("UPDATE nodes SET snmp_port=161\n")
65e2005b
VK
2778 _T("ALTER TABLE items ADD snmp_port integer\n")
2779 _T("UPDATE items SET snmp_port=0\n")
2780 _T("<END>");
2781
2782 CHK_EXEC(SQLBatch(batch));
2783
480e036b 2784 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("community")));
65e2005b
VK
2785 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("community")));
2786
480e036b 2787 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("usm_auth_password")));
65e2005b
VK
2788 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("usm_auth_password")));
2789
480e036b 2790 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("usm_priv_password")));
65e2005b
VK
2791 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("usm_priv_password")));
2792
480e036b 2793 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("snmp_oid")));
65e2005b
VK
2794 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("snmp_oid")));
2795
480e036b 2796 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("secret")));
65e2005b
VK
2797 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("secret")));
2798
480e036b 2799 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("agent_version")));
65e2005b
VK
2800 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("agent_version")));
2801
480e036b 2802 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("platform_name")));
65e2005b
VK
2803 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("platform_name")));
2804
480e036b 2805 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("uname")));
65e2005b
VK
2806 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("uname")));
2807
480e036b 2808 CHK_EXEC(SetColumnNullable(_T("items"), _T("name")));
65e2005b
VK
2809 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("name")));
2810
480e036b 2811 CHK_EXEC(SetColumnNullable(_T("items"), _T("description")));
65e2005b
VK
2812 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("description")));
2813
480e036b 2814 CHK_EXEC(SetColumnNullable(_T("items"), _T("transformation")));
65e2005b
VK
2815 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("transformation")));
2816
480e036b 2817 CHK_EXEC(SetColumnNullable(_T("items"), _T("instance")));
65e2005b
VK
2818 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("instance")));
2819
2820 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='217' WHERE var_name='SchemaVersion'")));
2821 return TRUE;
2822}
2823
480e036b
VK
2824/**
2825 * Upgrade from V215 to V216
2826 */
3f7c0fe4
VK
2827static BOOL H_UpgradeFromV215(int currVersion, int newVersion)
2828{
480e036b 2829 CHK_EXEC(SetColumnNullable(_T("ap_common"), _T("description")));
3f7c0fe4
VK
2830 CHK_EXEC(ConvertStrings(_T("ap_common"), _T("id"), _T("description")));
2831
a6c1f07f
VK
2832 if (g_iSyntax != DB_SYNTAX_SQLITE)
2833 CHK_EXEC(SQLQuery(_T("ALTER TABLE ap_config_files DROP COLUMN file_name")));
2834
480e036b 2835 CHK_EXEC(SetColumnNullable(_T("ap_config_files"), _T("file_content")));
a30fa363
VK
2836 CHK_EXEC(ConvertStrings(_T("ap_config_files"), _T("policy_id"), _T("file_content")));
2837
3f7c0fe4
VK
2838 CHK_EXEC(SQLQuery(_T("ALTER TABLE object_properties ADD guid varchar(36)")));
2839
2840 // Generate GUIDs for all objects
2841 DB_RESULT hResult = SQLSelect(_T("SELECT object_id FROM object_properties"));
2842 if (hResult != NULL)
2843 {
2844 int count = DBGetNumRows(hResult);
2845 for(int i = 0; i < count; i++)
2846 {
2847 uuid_t guid;
2848 TCHAR query[256], buffer[64];
2849
2850 uuid_generate(guid);
2851 _sntprintf(query, 256, _T("UPDATE object_properties SET guid='%s' WHERE object_id=%d"),
2852 uuid_to_string(guid, buffer), DBGetFieldULong(hResult, i, 0));
2853 CHK_EXEC(SQLQuery(query));
2854 }
2855 DBFreeResult(hResult);
2856 }
6f33021d 2857
3f7c0fe4
VK
2858 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='216' WHERE var_name='SchemaVersion'")));
2859 return TRUE;
2860}
2861
2862
021dcda7
VK
2863//
2864// Upgrade from V214 to V215
2865//
2866
2867static BOOL H_UpgradeFromV214(int currVersion, int newVersion)
2868{
2869 CHK_EXEC(CreateTable(_T("CREATE TABLE network_maps (")
2870 _T("id integer not null,")
2871 _T("map_type integer not null,")
2872 _T("layout integer not null,")
2873 _T("seed integer not null,")
2874 _T("background integer not null,")
2875 _T("PRIMARY KEY(id))")));
2876
2877 CHK_EXEC(CreateTable(_T("CREATE TABLE network_map_elements (")
2878 _T("map_id integer not null,")
2879 _T("element_id integer not null,")
2880 _T("element_type integer not null,")
2881 _T("element_data $SQL:TEXT not null,")
2882 _T("PRIMARY KEY(map_id,element_id))")));
2883
cce8f214
VK
2884 CHK_EXEC(CreateTable(_T("CREATE TABLE network_map_links (")
2885 _T("map_id integer not null,")
2886 _T("element1 integer not null,")
2887 _T("element2 integer not null,")
2888 _T("link_type integer not null,")
2889 _T("link_name varchar(255) null,")
2890 _T("connector_name1 varchar(255) null,")
2891 _T("connector_name2 varchar(255) null,")
2892 _T("PRIMARY KEY(map_id,element1,element2))")));
2893
021dcda7
VK
2894 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='215' WHERE var_name='SchemaVersion'")));
2895 return TRUE;
2896}
2897
480e036b
VK
2898/**
2899 * Upgrade from V213 to V214
2900 */
50da2d20
VK
2901static BOOL H_UpgradeFromV213(int currVersion, int newVersion)
2902{
480e036b 2903 CHK_EXEC(SetColumnNullable(_T("script_library"), _T("script_code")));
50da2d20
VK
2904 CHK_EXEC(ConvertStrings(_T("script_library"), _T("script_id"), _T("script_code")));
2905
480e036b 2906 CHK_EXEC(SetColumnNullable(_T("raw_dci_values"), _T("raw_value")));
50da2d20
VK
2907 CHK_EXEC(ConvertStrings(_T("raw_dci_values"), _T("item_id"), _T("raw_value")));
2908
2909 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='CREATE TABLE idata_%d (item_id integer not null,idata_timestamp integer not null,idata_value varchar(255) null)' WHERE var_name='IDataTableCreationCommand'")));
2910
2911 DB_RESULT hResult = SQLSelect(_T("SELECT id FROM nodes"));
2912 if (hResult != NULL)
2913 {
2914 int count = DBGetNumRows(hResult);
2915 for(int i = 0; i < count; i++)
2916 {
2917 TCHAR table[32];
2918
2919 DWORD nodeId = DBGetFieldULong(hResult, i, 0);
2920 _sntprintf(table, 32, _T("idata_%d"), nodeId);
480e036b 2921 CHK_EXEC(SetColumnNullable(table, _T("idata_value")));
50da2d20
VK
2922 }
2923 DBFreeResult(hResult);
2924 }
2925
2926 // Convert values for string DCIs from # encoded to normal form
2927 hResult = SQLSelect(_T("SELECT node_id,item_id FROM items WHERE datatype=4"));
2928 if (hResult != NULL)
2929 {
2930 int count = DBGetNumRows(hResult);
2931 for(int i = 0; i < count; i++)
2932 {
2933 TCHAR query[512];
2934
2935 DWORD nodeId = DBGetFieldULong(hResult, i, 0);
2936 DWORD dciId = DBGetFieldULong(hResult, i, 1);
2937
035a4d73 2938 if (IsNodeExist(nodeId))
50da2d20 2939 {
3f7c0fe4 2940 _sntprintf(query, 512, _T("SELECT idata_timestamp,idata_value FROM idata_%d WHERE item_id=%d AND idata_value LIKE '%%#%%'"), nodeId, dciId);
035a4d73
VK
2941 DB_RESULT hData = SQLSelect(query);
2942 if (hData != NULL)
50da2d20 2943 {
035a4d73
VK
2944 int valueCount = DBGetNumRows(hData);
2945 for(int j = 0; j < valueCount; j++)
2946 {
2947 TCHAR buffer[MAX_DB_STRING];
2948
2949 LONG ts = DBGetFieldLong(hData, j, 0);
2950 DBGetField(hData, j, 1, buffer, MAX_DB_STRING);
3f7c0fe4
VK
2951 DecodeSQLString(buffer);
2952
2953 _sntprintf(query, 512, _T("UPDATE idata_%d SET idata_value=%s WHERE item_id=%d AND idata_timestamp=%ld"),
2954 nodeId, (const TCHAR *)DBPrepareString(g_hCoreDB, buffer), dciId, (long)ts);
2955 CHK_EXEC(SQLQuery(query));
035a4d73
VK
2956 }
2957 DBFreeResult(hData);
50da2d20 2958 }
50da2d20
VK
2959 }
2960 }
2961 DBFreeResult(hResult);
2962 }
2963
2964 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='214' WHERE var_name='SchemaVersion'")));
50da2d20
VK
2965 return TRUE;
2966}
2967
480e036b
VK
2968/**
2969 * Upgrade from V212 to V213
2970 */
f57209fd
VK
2971static BOOL H_UpgradeFromV212(int currVersion, int newVersion)
2972{
480e036b
VK
2973 CHK_EXEC(SetColumnNullable(_T("items"), _T("custom_units_name")));
2974 CHK_EXEC(SetColumnNullable(_T("items"), _T("perftab_settings")));
f57209fd
VK
2975
2976 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("custom_units_name")));
2977 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("perftab_settings")));
2978
2979 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='213' WHERE var_name='SchemaVersion'")));
2980
2981 return TRUE;
2982}
2983
480e036b
VK
2984/**
2985 * Upgrade from V211 to V212
2986 */
1024e962
VK
2987static BOOL H_UpgradeFromV211(int currVersion, int newVersion)
2988{
480e036b
VK
2989 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("snmp_oid")));
2990 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("user_tag")));
2991 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("description")));
1024e962
VK
2992
2993 CHK_EXEC(ConvertStrings(_T("snmp_trap_cfg"), _T("trap_id"), _T("user_tag")));
2994 CHK_EXEC(ConvertStrings(_T("snmp_trap_cfg"), _T("trap_id"), _T("description")));
2995
2996 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='212' WHERE var_name='SchemaVersion'")));
2997
2998 return TRUE;
2999}
3000
480e036b
VK
3001/**
3002 * Upgrade from V210 to V211
3003 */
a8f60046
VK
3004static BOOL H_UpgradeFromV210(int currVersion, int newVersion)
3005{
6f33021d 3006 static TCHAR batch[] =
a8f60046
VK
3007 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
3008 _T(" (53,'SYS_DCI_UNSUPPORTED',2,1,'Status of DCI %1 (%5: %2) changed to UNSUPPORTED',")
3009 _T("'Generated when DCI status changed to UNSUPPORTED.#0D#0AParameters:#0D#0A")
3010 _T(" 1) DCI ID#0D#0A 2) DCI Name#0D#0A 3) DCI Description#0D#0A 4) DCI Origin code#0D#0A 5) DCI Origin name')\n")
3011 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
3012 _T(" (54,'SYS_DCI_DISABLED',1,1,'Status of DCI %1 (%5: %2) changed to DISABLED',")
3013 _T("'Generated when DCI status changed to DISABLED.#0D#0AParameters:#0D#0A")
3014 _T(" 1) DCI ID#0D#0A 2) DCI Name#0D#0A 3) DCI Description#0D#0A 4) DCI Origin code#0D#0A 5) DCI Origin name')\n")
3015 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
3016 _T(" (55,'SYS_DCI_ACTIVE',0,1,'Status of DCI %1 (%5: %2) changed to ACTIVE',")
3017 _T("'Generated when DCI status changed to ACTIVE.#0D#0AParameters:#0D#0A")
3018 _T(" 1) DCI ID#0D#0A 2) DCI Name#0D#0A 3) DCI Description#0D#0A 4) DCI Origin code#0D#0A 5) DCI Origin name')\n")
3019 _T("<END>");
3020
1024e962
VK
3021 CHK_EXEC(SQLBatch(batch));
3022 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='211' WHERE var_name='SchemaVersion'")));
a8f60046
VK
3023
3024 return TRUE;
3025}
3026
85ae39bc
VK
3027/**
3028 * Upgrade from V209 to V210
3029 */
43c1be79
VK
3030static BOOL H_UpgradeFromV209(int currVersion, int newVersion)
3031{
3032 if (!SQLQuery(_T("DELETE FROM metadata WHERE var_name like 'IDataIndexCreationCommand_%'")))
3033 if (!g_bIgnoreErrors)
3034 return FALSE;
3035
3036 const TCHAR *query;
3037 switch(g_iSyntax)
3038 {
3039 case DB_SYNTAX_PGSQL:
3040 query = _T("INSERT INTO metadata (var_name,var_value) VALUES ('IDataIndexCreationCommand_0','CREATE INDEX idx_idata_%d_timestamp_id ON idata_%d(idata_timestamp,item_id)')");
3041 break;
3042 case DB_SYNTAX_MSSQL:
3043 query = _T("INSERT INTO metadata (var_name,var_value) VALUES ('IDataIndexCreationCommand_0','CREATE CLUSTERED INDEX idx_idata_%d_id_timestamp ON idata_%d(item_id,idata_timestamp)')");
3044 break;
3045 default:
3046 query = _T("INSERT INTO metadata (var_name,var_value) VALUES ('IDataIndexCreationCommand_0','CREATE INDEX idx_idata_%d_id_timestamp ON idata_%d(item_id,idata_timestamp)')");
3047 break;
3048 }
3049
3050 if (!SQLQuery(query))
3051 if (!g_bIgnoreErrors)
3052 return FALSE;
3053
3054 ReindexIData();
3055
3056 if (!SQLQuery(_T("UPDATE metadata SET var_value='210' WHERE var_name='SchemaVersion'")))
3057 if (!g_bIgnoreErrors)
3058 return FALSE;
3059
3060 return TRUE;
3061}
3062
7541bca2
VK
3063/**
3064 * Upgrade from V208 to V209
3065 */
ab185583
VK
3066static BOOL H_UpgradeFromV208(int currVersion, int newVersion)
3067{
6f33021d 3068 static TCHAR batch[] =
ab185583
VK
3069 _T("ALTER TABLE users ADD auth_failures integer\n")
3070 _T("ALTER TABLE users ADD last_passwd_change integer\n")
3071 _T("ALTER TABLE users ADD min_passwd_length integer\n")
3072 _T("ALTER TABLE users ADD disabled_until integer\n")
3073 _T("ALTER TABLE users ADD last_login integer\n")
3074 _T("ALTER TABLE users ADD password_history $SQL:TEXT\n")
3075 _T("UPDATE users SET auth_failures=0,last_passwd_change=0,min_passwd_length=-1,disabled_until=0,last_login=0\n")
3076 _T("<END>");
3077
3078 if (!SQLBatch(batch))
3079 if (!g_bIgnoreErrors)
3080 return FALSE;
3081
3082 if (!CreateConfigParam(_T("PasswordHistoryLength"), _T("0"), 1, 0))
3083 if (!g_bIgnoreErrors)
3084 return FALSE;
3085
0f1ddb74 3086 if (!CreateConfigParam(_T("IntruderLockoutThreshold"), _T("0"), 1, 0))
ab185583
VK
3087 if (!g_bIgnoreErrors)
3088 return FALSE;
3089
3090 if (!CreateConfigParam(_T("IntruderLockoutTime"), _T("30"), 1, 0))
3091 if (!g_bIgnoreErrors)
3092 return FALSE;
3093
3094 if (!CreateConfigParam(_T("MinPasswordLength"), _T("0"), 1, 0))
3095 if (!g_bIgnoreErrors)
3096 return FALSE;
3097
3098 if (!CreateConfigParam(_T("PasswordComplexity"), _T("0"), 1, 0))
3099 if (!g_bIgnoreErrors)
3100 return FALSE;
3101
3102 if (!CreateConfigParam(_T("PasswordExpiration"), _T("0"), 1, 0))
3103 if (!g_bIgnoreErrors)
3104 return FALSE;
3105
3106 if (!CreateConfigParam(_T("BlockInactiveUserAccounts"), _T("0"), 1, 0))
3107 if (!g_bIgnoreErrors)
3108 return FALSE;
3109
3110 if (!SQLQuery(_T("UPDATE metadata SET var_value='209' WHERE var_name='SchemaVersion'")))
3111 if (!g_bIgnoreErrors)
3112 return FALSE;
3113
3114 return TRUE;
3115}
3116
3117
80d3565a
VK
3118//
3119// Upgrade from V207 to V208
3120//
3121
3122static BOOL H_UpgradeFromV207(int currVersion, int newVersion)
3123{
3124 if (!SQLQuery(_T("ALTER TABLE items ADD system_tag varchar(255)")))
3125 if (!g_bIgnoreErrors)
3126 return FALSE;
3127
3128 if (!SQLQuery(_T("UPDATE metadata SET var_value='208' WHERE var_name='SchemaVersion'")))
3129 if (!g_bIgnoreErrors)
3130 return FALSE;
3131
3132 return TRUE;
3133}
3134
3135
5ab2f1ab
VK
3136//
3137// Upgrade from V206 to V207
3138//
3139
3140static BOOL H_UpgradeFromV206(int currVersion, int newVersion)
3141{
3142 if (!CreateConfigParam(_T("RADIUSSecondaryServer"), _T("none"), 1, 0))
3143 if (!g_bIgnoreErrors)
3144 return FALSE;
3145
3146 if (!CreateConfigParam(_T("RADIUSSecondarySecret"), _T("netxms"), 1, 0))
3147 if (!g_bIgnoreErrors)
3148 return FALSE;
3149
3150 if (!CreateConfigParam(_T("RADIUSSecondaryPort"), _T("1645"), 1, 0))
3151 if (!g_bIgnoreErrors)
3152 return FALSE;
3153
3154 if (!CreateConfigParam(_T("ExternalAuditServer"), _T("none"), 1, 1))
3155 if (!g_bIgnoreErrors)
3156 return FALSE;
3157
3158 if (!CreateConfigParam(_T("ExternalAuditPort"), _T("514"), 1, 1))
3159 if (!g_bIgnoreErrors)
3160 return FALSE;
3161
3162 if (!CreateConfigParam(_T("ExternalAuditFacility"), _T("13"), 1, 1))
3163 if (!g_bIgnoreErrors)
3164 return FALSE;
3165
3166 if (!CreateConfigParam(_T("ExternalAuditSeverity"), _T("5"), 1, 1))
3167 if (!g_bIgnoreErrors)
3168 return FALSE;
3169
3170 if (!CreateConfigParam(_T("ExternalAuditTag"), _T("netxmsd-audit"), 1, 1))
3171 if (!g_bIgnoreErrors)
3172 return FALSE;
3173
3174 if (!SQLQuery(_T("UPDATE metadata SET var_value='207' WHERE var_name='SchemaVersion'")))
3175 if (!g_bIgnoreErrors)
3176 return FALSE;
3177
3178 return TRUE;
3179}
3180
3181
ce7565e7
VK
3182//
3183// Upgrade from V205 to V206
3184//
3185
3186static BOOL H_UpgradeFromV205(int currVersion, int newVersion)
3187{
a4743a0f
VK
3188 if (g_iSyntax == DB_SYNTAX_ORACLE)
3189 {
3190 static TCHAR oraBatch[] =
3191 _T("ALTER TABLE audit_log MODIFY message null\n")
3192 _T("ALTER TABLE event_log MODIFY event_message null\n")
3193 _T("ALTER TABLE event_log MODIFY user_tag null\n")
3194 _T("ALTER TABLE syslog MODIFY hostname null\n")
3195 _T("ALTER TABLE syslog MODIFY msg_tag null\n")
3196 _T("ALTER TABLE syslog MODIFY msg_text null\n")
3197 _T("ALTER TABLE snmp_trap_log MODIFY trap_varlist null\n")
3198 _T("<END>");
3199
3200 if (!SQLBatch(oraBatch))
3201 if (!g_bIgnoreErrors)
3202 return FALSE;
3203 }
ce7565e7 3204
a4743a0f
VK
3205 bool clearLogs = GetYesNo(_T("This database upgrade requires log conversion. This can take significant amount of time ")
3206 _T("(up to few hours for large databases). If preserving all log records is not very important, it is ")
3207 _T("recommended to clear logs befor conversion. Clear logs?"));
ce7565e7 3208
a4743a0f
VK
3209 if (clearLogs)
3210 {
3211 if (!SQLQuery(_T("DELETE FROM audit_log")))
3212 if (!g_bIgnoreErrors)
3213 return FALSE;
ce7565e7 3214
a4743a0f
VK
3215 if (!SQLQuery(_T("DELETE FROM event_log")))
3216 if (!g_bIgnoreErrors)
3217 return FALSE;
3218
3219 if (!SQLQuery(_T("DELETE FROM syslog")))
3220 if (!g_bIgnoreErrors)
3221 return FALSE;
3222
3223 if (!SQLQuery(_T("DELETE FROM snmp_trap_log")))
3224 if (!g_bIgnoreErrors)
3225 return FALSE;
3226 }
3227 else
3228 {
3229 // Convert event log
08b214c6 3230 if (!ConvertStrings(_T("event_log"), _T("event_id"), _T("event_message")))
a4743a0f
VK
3231 if (!g_bIgnoreErrors)
3232 return FALSE;
08b214c6 3233 if (!ConvertStrings(_T("event_log"), _T("event_id"), _T("user_tag")))
a4743a0f
VK
3234 if (!g_bIgnoreErrors)
3235 return FALSE;
3236
3237 // Convert audit log
08b214c6 3238 if (!ConvertStrings(_T("audit_log"), _T("record_id"), _T("message")))
a4743a0f
VK
3239 if (!g_bIgnoreErrors)
3240 return FALSE;
3241
3242 // Convert syslog
08b214c6 3243 if (!ConvertStrings(_T("syslog"), _T("msg_id"), _T("msg_text")))
a4743a0f
VK
3244 if (!g_bIgnoreErrors)
3245 return FALSE;
3246
3247 // Convert SNMP trap log
08b214c6 3248 if (!ConvertStrings(_T("snmp_trap_log"), _T("trap_id"), _T("trap_varlist")))
a4743a0f
VK
3249 if (!g_bIgnoreErrors)
3250 return FALSE;
3251 }
ce7565e7
VK
3252
3253 if (!SQLQuery(_T("UPDATE metadata SET var_value='206' WHERE var_name='SchemaVersion'")))
3254 if (!g_bIgnoreErrors)
3255 return FALSE;
3256
3257 return TRUE;
3258}
3259
3260
df8a4ca2
VK
3261//
3262// Upgrade from V204 to V205
3263//
3264
3265static BOOL H_UpgradeFromV204(int currVersion, int newVersion)
3266{
3267 if (!CreateTable(_T("CREATE TABLE usm_credentials (")
3268 _T("id integer not null,")
3269 _T("user_name varchar(255) not null,")
3270 _T("auth_method integer not null,")
3271 _T("priv_method integer not null,")
3272 _T("auth_password varchar(255),")
3273 _T("priv_password varchar(255),")
3274 _T("PRIMARY KEY(id))")))
3275 if (!g_bIgnoreErrors)
3276 return FALSE;
3277
3278 if (!SQLQuery(_T("UPDATE metadata SET var_value='205' WHERE var_name='SchemaVersion'")))
3279 if (!g_bIgnoreErrors)
3280 return FALSE;
3281
3282 return TRUE;
3283}
3284
3285
e2babedf
VK
3286//
3287// Upgrade from V203 to V204
3288//
3289
3290static BOOL H_UpgradeFromV203(int currVersion, int newVersion)
3291{
6f33021d 3292 static TCHAR batch[] =
e2babedf
VK
3293 _T("ALTER TABLE object_properties ADD location_type integer\n")
3294 _T("ALTER TABLE object_properties ADD latitude varchar(20)\n")
3295 _T("ALTER TABLE object_properties ADD longitude varchar(20)\n")
3296 _T("UPDATE object_properties SET location_type=0\n")
3297 _T("ALTER TABLE object_properties DROP COLUMN image_id\n")
3298 _T("<END>");
3299
3300 if (!SQLBatch(batch))
3301 if (!g_bIgnoreErrors)
3302 return FALSE;
3303
3304 if (!CreateConfigParam(_T("ConnectionPoolBaseSize"), _T("5"), 1, 1))
3305 if (!g_bIgnoreErrors)
3306 return FALSE;
3307
3308 if (!CreateConfigParam(_T("ConnectionPoolMaxSize"), _T("20"), 1, 1))
3309 if (!g_bIgnoreErrors)
3310 return FALSE;
3311
3312 if (!CreateConfigParam(_T("ConnectionPoolCooldownTime"), _T("300"), 1, 1))
3313 if (!g_bIgnoreErrors)
3314 return FALSE;
3315
a4743a0f
VK
3316 if (g_iSyntax == DB_SYNTAX_ORACLE)
3317 {
3318 if (!SQLQuery(_T("ALTER TABLE object_properties MODIFY comments null\n")))
3319 if (!g_bIgnoreErrors)
3320 return FALSE;
3321 }
3322
08b214c6 3323 if (!ConvertStrings(_T("object_properties"), _T("object_id"), _T("comments")))
e2babedf
VK
3324 if (!g_bIgnoreErrors)
3325 return FALSE;
3326
3327 if (!SQLQuery(_T("UPDATE metadata SET var_value='204' WHERE var_name='SchemaVersion'")))
3328 if (!g_bIgnoreErrors)
3329 return FALSE;
3330
3331 return TRUE;
3332}
3333
3334
7cda0d53
VK
3335//
3336// Upgrade from V202 to V203
3337//
3338
3339static BOOL H_UpgradeFromV202(int currVersion, int newVersion)
3340{
6f33021d 3341 static TCHAR batch[] =
7cda0d53
VK
3342 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text)")
3343 _T(" VALUES (20,'&Info->Topology table (LLDP)',2,'Topology Table',1,' ','Show topology table (LLDP)','#00')\n")
3344 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3345 _T(" VALUES (20,0,'Chassis ID','.1.0.8802.1.1.2.1.4.1.1.5',0,0)\n")
3346 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3347 _T(" VALUES (20,1,'Local port','.1.0.8802.1.1.2.1.4.1.1.2',5,0)\n")
3348 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3349 _T(" VALUES (20,2,'System name','.1.0.8802.1.1.2.1.4.1.1.9',0,0)\n")
3350 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3351 _T(" VALUES (20,3,'System description','.1.0.8802.1.1.2.1.4.1.1.10',0,0)\n")
3352 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3353 _T(" VALUES (20,4,'Remote port ID','.1.0.8802.1.1.2.1.4.1.1.7',4,0)\n")
3354 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3355 _T(" VALUES (20,5,'Remote port description','.1.0.8802.1.1.2.1.4.1.1.8',0,0)\n")
3356 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (20,-2147483648)\n")
3357 _T("<END>");
3358
3359 if (!SQLBatch(batch))
3360 if (!g_bIgnoreErrors)
3361 return FALSE;
3362
3363 if (!SQLQuery(_T("UPDATE metadata SET var_value='203' WHERE var_name='SchemaVersion'")))
3364 if (!g_bIgnoreErrors)
3365 return FALSE;
3366
3367 return TRUE;
3368}
3369
3370
643c9dcb
VK
3371//
3372// Upgrade from V201 to V202
3373//
3374
3375static BOOL H_UpgradeFromV201(int currVersion, int newVersion)
3376{
a4743a0f
VK
3377 if (g_iSyntax == DB_SYNTAX_ORACLE)
3378 {
3379 static TCHAR oraBatch[] =
3380 _T("ALTER TABLE alarms MODIFY message null\n")
3381 _T("ALTER TABLE alarms MODIFY alarm_key null\n")
3382 _T("ALTER TABLE alarms MODIFY hd_ref null\n")
3383 _T("<END>");
3384
3385 if (!SQLBatch(oraBatch))
3386 if (!g_bIgnoreErrors)
3387 return FALSE;
3388 }
3389
08b214c6 3390 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("message")))
643c9dcb
VK
3391 if (!g_bIgnoreErrors)
3392 return FALSE;
08b214c6 3393 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("alarm_key")))
643c9dcb
VK
3394 if (!g_bIgnoreErrors)
3395 return FALSE;
08b214c6 3396 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("hd_ref")))
643c9dcb
VK
3397 if (!g_bIgnoreErrors)
3398 return FALSE;
3399
3400 if (!SQLQuery(_T("UPDATE metadata SET var_value='202' WHERE var_name='SchemaVersion'")))
3401 if (!g_bIgnoreErrors)
3402 return FALSE;
3403
3404 return TRUE;
3405}
3406
3407
31cc1924
VK
3408//
3409// Upgrade from V200 to V201
3410//
3411
3412static BOOL H_UpgradeFromV200(int currVersion, int newVersion)
3413{
3414 static TCHAR batch[] =
3415 _T("ALTER TABLE nodes ADD usm_auth_password varchar(127)\n")
3416 _T("ALTER TABLE nodes ADD usm_priv_password varchar(127)\n")
3417 _T("ALTER TABLE nodes ADD usm_methods integer\n")
e8daf6d5 3418 _T("UPDATE nodes SET usm_auth_password='#00',usm_priv_password='#00',usm_methods=0\n")
31cc1924 3419 _T("<END>");
6f33021d 3420
31cc1924
VK
3421 if (!SQLBatch(batch))
3422 if (!g_bIgnoreErrors)
3423 return FALSE;
3424
3425 if (!SQLQuery(_T("UPDATE metadata SET var_value='201' WHERE var_name='SchemaVersion'")))
3426 if (!g_bIgnoreErrors)
3427 return FALSE;
3428
3429 return TRUE;
3430}
3431
3432
45d84f8a
VK
3433//
3434// Upgrade from V92 to V200
31cc1924 3435// or from V93 to V201
e2babedf
VK
3436// or from V94 to V202
3437// or from V95 to V203
ce7565e7
VK
3438// or from V96 to V204
3439// or from V97 to V205
3440// or from V98 to V206
43c1be79 3441// or from V99 to V207
45d84f8a
VK
3442//
3443
e2babedf 3444static BOOL H_UpgradeFromV9x(int currVersion, int newVersion)
45d84f8a
VK
3445{
3446 if (!CreateTable(_T("CREATE TABLE ap_common (")
3447 _T("id integer not null,")
3448 _T("policy_type integer not null,")
3449 _T("version integer not null,")
3450 _T("description $SQL:TEXT not null,")
3451 _T("PRIMARY KEY(id))")))
3452 if (!g_bIgnoreErrors)
3453 return FALSE;
3454
3455 if (!CreateTable(_T("CREATE TABLE ap_bindings (")
3456 _T("policy_id integer not null,")
3457 _T("node_id integer not null,")
3458 _T("PRIMARY KEY(policy_id,node_id))")))
3459 if (!g_bIgnoreErrors)
3460 return FALSE;
3461
3462 if (!CreateTable(_T("CREATE TABLE ap_config_files (")
3463 _T("policy_id integer not null,")
3464 _T("file_name varchar(63) not null,")
3465 _T("file_content $SQL:TEXT not null,")
3466 _T("PRIMARY KEY(policy_id))")))
3467 if (!g_bIgnoreErrors)
3468 return FALSE;
3469
31cc1924
VK
3470 TCHAR query[256];
3471 _sntprintf(query, 256, _T("UPDATE metadata SET var_value='%d' WHERE var_name='SchemaVersion'"), newVersion);
3472 if (!SQLQuery(query))
45d84f8a
VK
3473 if (!g_bIgnoreErrors)
3474 return FALSE;
3475
3476 return TRUE;
3477}
3478
3479
43c1be79 3480//
50da2d20
VK
3481// Upgrade from V100 to V214
3482// or from V101 to V214
3483// or from V102 to V214
3484// or from V103 to V214
3485// or from V104 to V214
43c1be79
VK
3486//
3487
a8f60046 3488static BOOL H_UpgradeFromV10x(int currVersion, int newVersion)
43c1be79 3489{
50da2d20 3490 if (!H_UpgradeFromV9x(currVersion, 207))
43c1be79
VK
3491 return FALSE;
3492
3493 // Now database at V207 level
50da2d20
VK
3494 // V100 already has changes V209 -> V210, but missing V207 -> V209 and V210 -> V214 changes
3495 // V101 already has changes V209 -> V211, but missing V207 -> V209 and V211 -> V214 changes
3496 // V102 already has changes V209 -> V212, but missing V207 -> V209 and V212 -> V214 changes
3497 // V103 already has changes V209 -> V213, but missing V207 -> V209 and V213 -> V214 changes
3498 // V104 already has changes V209 -> V214, but missing V207 -> V209 changes
43c1be79
VK
3499
3500 if (!H_UpgradeFromV207(207, 208))
3501 return FALSE;
3502
a6c1f07f 3503 if (!H_UpgradeFromV208(208, 209))
43c1be79
VK
3504 return FALSE;
3505
a8f60046 3506 if (currVersion == 100)
50da2d20
VK
3507 if (!H_UpgradeFromV210(210, 211))
3508 return FALSE;
a8f60046 3509
1024e962 3510 if (currVersion < 102)
50da2d20
VK
3511 if (!H_UpgradeFromV211(211, 212))
3512 return FALSE;
1024e962 3513
f57209fd 3514 if (currVersion < 103)
50da2d20
VK
3515 if (!H_UpgradeFromV212(212, 213))
3516 return FALSE;
3517
3518 if (currVersion < 104)