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