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