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