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