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