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