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