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