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