strip.pl added to dist
[public/netxms.git] / src / server / tools / nxdbmgr / upgrade.cpp
CommitLineData
6f33021d 1/*
5039dede 2** nxdbmgr - NetXMS database manager
035745fc 3** Copyright (C) 2004-2014 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
4f50e45c
VK
25/**
26 * Externals
27 */
7a41a06e
VK
28BOOL MigrateMaps();
29
4f50e45c
VK
30/**
31 * Create table
32 */
5039dede
AK
33static BOOL CreateTable(const TCHAR *pszQuery)
34{
5039dede 35 BOOL bResult;
7618e362 36 String query(pszQuery);
5039dede 37
6bcafa2d
VK
38 query.replace(_T("$SQL:TEXT"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]);
39 query.replace(_T("$SQL:TXT4K"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT4K]);
40 query.replace(_T("$SQL:INT64"), g_pszSqlType[g_iSyntax][SQL_TYPE_INT64]);
5039dede 41 if (g_iSyntax == DB_SYNTAX_MYSQL)
7618e362
VK
42 query += g_pszTableSuffix;
43 bResult = SQLQuery(query);
5039dede
AK
44 return bResult;
45}
46
4f50e45c
VK
47/**
48 * Create configuration parameter if it doesn't exist (unless bForceUpdate set to true)
49 */
b3eb058b 50BOOL CreateConfigParam(const TCHAR *pszName, const TCHAR *pszValue, int iVisible, int iNeedRestart, BOOL bForceUpdate)
5039dede 51{
42475f3e 52 TCHAR szQuery[1024];
5039dede
AK
53 DB_RESULT hResult;
54 BOOL bVarExist = FALSE, bResult = TRUE;
55
56 // Check for variable existence
08b214c6 57 _sntprintf(szQuery, 1024, _T("SELECT var_value FROM config WHERE var_name='%s'"), pszName);
5039dede
AK
58 hResult = DBSelect(g_hCoreDB, szQuery);
59 if (hResult != 0)
60 {
61 if (DBGetNumRows(hResult) > 0)
62 bVarExist = TRUE;
63 DBFreeResult(hResult);
64 }
65
66 if (!bVarExist)
67 {
08b214c6 68 _sntprintf(szQuery, 1024, _T("INSERT INTO config (var_name,var_value,is_visible,")
6f33021d 69 _T("need_server_restart) VALUES (%s,%s,%d,%d)"),
70 (const TCHAR *)DBPrepareString(g_hCoreDB, pszName, 63),
42475f3e 71 (const TCHAR *)DBPrepareString(g_hCoreDB, pszValue, 255), iVisible, iNeedRestart);
5039dede
AK
72 bResult = SQLQuery(szQuery);
73 }
74 else if (bForceUpdate)
75 {
42475f3e
VK
76 _sntprintf(szQuery, 1024, _T("UPDATE config SET var_value=%s WHERE var_name=%s"),
77 (const TCHAR *)DBPrepareString(g_hCoreDB, pszValue, 255), (const TCHAR *)DBPrepareString(g_hCoreDB, pszName, 63));
5039dede
AK
78 bResult = SQLQuery(szQuery);
79 }
80 return bResult;
81}
82
4f50e45c
VK
83/**
84 * Set primary key constraint
85 */
5039dede
AK
86static BOOL SetPrimaryKey(const TCHAR *table, const TCHAR *key)
87{
88 TCHAR query[4096];
89
90 if (g_iSyntax == DB_SYNTAX_SQLITE)
91 return TRUE; // SQLite does not support adding constraints
6f33021d 92
5039dede
AK
93 _sntprintf(query, 4096, _T("ALTER TABLE %s ADD PRIMARY KEY (%s)"), table, key);
94 return SQLQuery(query);
95}
96
4f50e45c
VK
97/**
98 * Drop primary key from table
99 */
9bfc9a6b
VK
100static BOOL DropPrimaryKey(const TCHAR *table)
101{
102 TCHAR query[1024];
103 DB_RESULT hResult;
104 BOOL success;
105
106 switch(g_iSyntax)
107 {
108 case DB_SYNTAX_ORACLE:
109 case DB_SYNTAX_MYSQL:
110 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP PRIMARY KEY"), table);
111 success = SQLQuery(query);
112 break;
113 case DB_SYNTAX_PGSQL:
114 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP CONSTRAINT %s_pkey"), table, table);
115 success = SQLQuery(query);
116 break;
117 case DB_SYNTAX_MSSQL:
118 success = FALSE;
119 _sntprintf(query, 1024, _T("SELECT name FROM sysobjects WHERE xtype='PK' AND parent_obj=OBJECT_ID('%s')"), table);
120 hResult = SQLSelect(query);
121 if (hResult != NULL)
122 {
123 if (DBGetNumRows(hResult) > 0)
124 {
125 TCHAR objName[512];
126
127 DBGetField(hResult, 0, 0, objName, 512);
128 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP CONSTRAINT %s"), table, objName);
129 success = SQLQuery(query);
130 }
131 DBFreeResult(hResult);
132 }
133 break;
134 default: // Unsupported DB engine
135 success = FALSE;
136 break;
137 }
138 return success;
139}
140
4f50e45c
VK
141/**
142 * Convert strings from # encoded form to normal form
143 */
d6bf58f9 144static BOOL ConvertStrings(const TCHAR *table, const TCHAR *idColumn, const TCHAR *idColumn2, const TCHAR *column, bool isStringId)
643c9dcb
VK
145{
146 DB_RESULT hResult;
147 TCHAR *query;
148 int queryLen = 512;
149 BOOL success = FALSE;
150
c29fb885 151 query = (TCHAR *)malloc(queryLen * sizeof(TCHAR));
fe12a1ea 152
a4743a0f
VK
153 switch(g_iSyntax)
154 {
155 case DB_SYNTAX_MSSQL:
9f6712bc 156 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE CAST(%s AS nvarchar(4000))=N'#00'"), table, column, column);
a4743a0f
VK
157 break;
158 case DB_SYNTAX_ORACLE:
159 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE to_char(%s)='#00'"), table, column, column);
160 break;
161 default:
162 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE %s='#00'"), table, column, column);
163 break;
164 }
fe12a1ea
VK
165 if (!SQLQuery(query))
166 {
167 free(query);
168 return FALSE;
169 }
170
6f33021d 171 _sntprintf(query, queryLen, _T("SELECT %s,%s%s%s FROM %s WHERE %s LIKE '%%#%%'"),
98cd01bb 172 idColumn, column, (idColumn2 != NULL) ? _T(",") : _T(""), (idColumn2 != NULL) ? idColumn2 : _T(""), table, column);
643c9dcb
VK
173 hResult = SQLSelect(query);
174 if (hResult == NULL)
175 {
176 free(query);
177 return FALSE;
178 }
179
180 int count = DBGetNumRows(hResult);
181 for(int i = 0; i < count; i++)
182 {
643c9dcb 183 TCHAR *value = DBGetField(hResult, i, 1, NULL, 0);
035a4d73 184 if (_tcschr(value, _T('#')) != NULL)
643c9dcb 185 {
035a4d73
VK
186 DecodeSQLString(value);
187 String newValue = DBPrepareString(g_hCoreDB, value);
188 if ((int)newValue.getSize() + 256 > queryLen)
189 {
190 queryLen = newValue.getSize() + 256;
c29fb885 191 query = (TCHAR *)realloc(query, queryLen * sizeof(TCHAR));
035a4d73 192 }
d6bf58f9 193 if (isStringId)
98cd01bb 194 {
d6bf58f9
VK
195 TCHAR *id = DBGetField(hResult, i, 0, NULL, 0);
196 if (idColumn2 != NULL)
197 {
198 TCHAR *id2 = DBGetField(hResult, i, 2, NULL, 0);
199 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=%s AND %s=%s"),
200 table, column, (const TCHAR *)newValue,
6f33021d 201 idColumn, (const TCHAR *)DBPrepareString(g_hCoreDB, id),
d6bf58f9
VK
202 idColumn2, (const TCHAR *)DBPrepareString(g_hCoreDB, id2));
203 }
204 else
205 {
206 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=%s"), table, column,
207 (const TCHAR *)newValue, idColumn, (const TCHAR *)DBPrepareString(g_hCoreDB, id));
208 }
209 free(id);
98cd01bb
VK
210 }
211 else
212 {
d6bf58f9
VK
213 INT64 id = DBGetFieldInt64(hResult, i, 0);
214 if (idColumn2 != NULL)
215 {
216 INT64 id2 = DBGetFieldInt64(hResult, i, 2);
6f33021d 217 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=") INT64_FMT _T(" AND %s=") INT64_FMT,
d6bf58f9
VK
218 table, column, (const TCHAR *)newValue, idColumn, id, idColumn2, id2);
219 }
220 else
221 {
222 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=") INT64_FMT, table, column,
223 (const TCHAR *)newValue, idColumn, id);
224 }
98cd01bb 225 }
035a4d73
VK
226 if (!SQLQuery(query))
227 goto cleanup;
643c9dcb 228 }
643c9dcb
VK
229 }
230 success = TRUE;
231
232cleanup:
233 DBFreeResult(hResult);
a4743a0f 234 free(query);
643c9dcb
VK
235 return success;
236}
237
98cd01bb
VK
238static BOOL ConvertStrings(const TCHAR *table, const TCHAR *idColumn, const TCHAR *column)
239{
d6bf58f9 240 return ConvertStrings(table, idColumn, NULL, column, false);
98cd01bb
VK
241}
242
4f50e45c 243/**
70ffb771 244 * Set column nullable (currently only Oracle and PostgreSQL)
4f50e45c 245 */
480e036b 246static BOOL SetColumnNullable(const TCHAR *table, const TCHAR *column)
1024e962
VK
247{
248 TCHAR query[1024] = _T("");
249
250 switch(g_iSyntax)
251 {
252 case DB_SYNTAX_ORACLE:
253 _sntprintf(query, 1024, _T("DECLARE already_null EXCEPTION; ")
254 _T("PRAGMA EXCEPTION_INIT(already_null, -1451); ")
f57209fd
VK
255 _T("BEGIN EXECUTE IMMEDIATE 'ALTER TABLE %s MODIFY %s null'; ")
256 _T("EXCEPTION WHEN already_null THEN null; END;"), table, column);
1024e962 257 break;
480e036b
VK
258 case DB_SYNTAX_PGSQL:
259 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s DROP NOT NULL"), table, column);
260 break;
1024e962
VK
261 default:
262 break;
263 }
264
265 return (query[0] != 0) ? SQLQuery(query) : TRUE;
266}
267
480e036b
VK
268/**
269 * Resize varchar column
270 */
271static BOOL ResizeColumn(const TCHAR *table, const TCHAR *column, int newSize)
272{
273 TCHAR query[1024];
274
275 switch(g_iSyntax)
276 {
277 case DB_SYNTAX_DB2:
278 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s SET DATA TYPE varchar(%d)"), table, column, newSize);
279 break;
280 case DB_SYNTAX_MSSQL:
281 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s varchar(%d)"), table, column, newSize);
282 break;
283 case DB_SYNTAX_PGSQL:
284 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s TYPE varchar(%d)"), table, column, newSize);
285 break;
286 case DB_SYNTAX_SQLITE:
287 /* TODO: add SQLite support */
288 query[0] = 0;
289 break;
290 default:
291 _sntprintf(query, 1024, _T("ALTER TABLE %s MODIFY %s varchar(%d)"), table, column, newSize);
292 break;
293 }
294
295 return (query[0] != 0) ? SQLQuery(query) : TRUE;
296}
297
4f50e45c
VK
298/**
299 * Create new event template
300 */
aa16f82b
VK
301static BOOL CreateEventTemplate(int code, const TCHAR *name, int severity, int flags, const TCHAR *message, const TCHAR *description)
302{
480e036b 303 TCHAR query[4096];
aa16f82b 304
480e036b
VK
305 _sntprintf(query, 4096, _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (%d,'%s',%d,%d,%s,%s)"),
306 code, name, severity, flags, (const TCHAR *)DBPrepareString(g_hCoreDB, message),
307 (const TCHAR *)DBPrepareString(g_hCoreDB, description));
aa16f82b
VK
308 return SQLQuery(query);
309}
310
22aaa779
VK
311/**
312 * Re-create TDATA tables
313 */
1d4f7890 314static BOOL RecreateTData(const TCHAR *className, bool multipleTables)
22aaa779 315{
1d4f7890 316 TCHAR query[1024];
22aaa779
VK
317 _sntprintf(query, 256, _T("SELECT id FROM %s"), className);
318 DB_RESULT hResult = SQLSelect(query);
319 if (hResult != NULL)
320 {
321 int count = DBGetNumRows(hResult);
322 for(int i = 0; i < count; i++)
323 {
324 DWORD id = DBGetFieldULong(hResult, i, 0);
325
1d4f7890
VK
326 if (multipleTables)
327 {
328 _sntprintf(query, 1024, _T("DROP TABLE tdata_rows_%d\nDROP TABLE tdata_records_%d\nDROP TABLE tdata_%d\n<END>"), id, id, id);
329 }
330 else
331 {
332 _sntprintf(query, 256, _T("DROP TABLE tdata_%d\n<END>"), id);
333 }
334 if (!SQLBatch(query))
22aaa779
VK
335 {
336 if (!g_bIgnoreErrors)
337 {
338 DBFreeResult(hResult);
339 return FALSE;
340 }
341 }
342
343 if (!CreateTDataTables(id))
344 {
345 if (!g_bIgnoreErrors)
346 {
347 DBFreeResult(hResult);
348 return FALSE;
349 }
350 }
351 }
352 DBFreeResult(hResult);
353 }
354 else
355 {
356 if (!g_bIgnoreErrors)
357 return FALSE;
358 }
359 return TRUE;
360}
361
8deadd79
VK
362/**
363 * Upgrade from V316 to V317
364 */
365static BOOL H_UpgradeFromV316(int currVersion, int newVersion)
366{
367 CHK_EXEC(CreateConfigParam(_T("MinViewRefreshInterval"), _T("1000"), 1, 0));
368 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='317' WHERE var_name='SchemaVersion'")));
369 return TRUE;
370}
371
23ed00c4
VK
372/**
373 * Upgrade from V315 to V316
374 */
375static BOOL H_UpgradeFromV315(int currVersion, int newVersion)
376{
377 static TCHAR batch[] =
378 _T("ALTER TABLE access_points ADD ap_state integer\n")
379 _T("UPDATE access_points SET ap_state=0\n")
380 _T("<END>");
381 CHK_EXEC(SQLBatch(batch));
382
383 CHK_EXEC(CreateEventTemplate(EVENT_AP_ADOPTED, _T("SYS_AP_ADOPTED"), SEVERITY_NORMAL, EF_LOG,
384 _T("Access point %2 changed state to ADOPTED"),
385 _T("Generated when access point state changes to ADOPTED.\r\n")
386 _T("Parameters:\r\n")
387 _T(" 1) Access point object ID\r\n")
388 _T(" 2) Access point name\r\n")
389 _T(" 3) Access point MAC address\r\n")
390 _T(" 4) Access point IP address\r\n")
391 _T(" 5) Access point vendor name\r\n")
392 _T(" 6) Access point model\r\n")
393 _T(" 7) Access point serial number")));
394
395 CHK_EXEC(CreateEventTemplate(EVENT_AP_UNADOPTED, _T("SYS_AP_UNADOPTED"), SEVERITY_MAJOR, EF_LOG,
396 _T("Access point %2 changed state to UNADOPTED"),
397 _T("Generated when access point state changes to UNADOPTED.\r\n")
398 _T("Parameters:\r\n")
399 _T(" 1) Access point object ID\r\n")
400 _T(" 2) Access point name\r\n")
401 _T(" 3) Access point MAC address\r\n")
402 _T(" 4) Access point IP address\r\n")
403 _T(" 5) Access point vendor name\r\n")
404 _T(" 6) Access point model\r\n")
405 _T(" 7) Access point serial number")));
406
407 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='316' WHERE var_name='SchemaVersion'")));
408 return TRUE;
409}
410
b2042b58
VK
411/**
412 * Upgrade from V314 to V315
413 */
414static BOOL H_UpgradeFromV314(int currVersion, int newVersion)
415{
416 static TCHAR batch[] =
417 _T("ALTER TABLE thresholds ADD match_count integer\n")
418 _T("UPDATE thresholds SET match_count=0 WHERE current_state=0\n")
419 _T("UPDATE thresholds SET match_count=1 WHERE current_state<>0\n")
420 _T("<END>");
421 CHK_EXEC(SQLBatch(batch));
422 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='315' WHERE var_name='SchemaVersion'")));
423 return TRUE;
424}
425
2d7ee2e0 426/**
427 * Upgrade from V313 to V314
428 */
429static BOOL H_UpgradeFromV313(int currVersion, int newVersion)
430{
b2042b58 431 // Replace double backslash with single backslash in all "file download" (code 7) object tools
2d7ee2e0 432 DB_RESULT hResult = SQLSelect(_T("SELECT tool_id, tool_data FROM object_tools WHERE tool_type=7"));
433 if (hResult != NULL)
434 {
435 int count = DBGetNumRows(hResult);
436 for(int i = 0; i < count; i++)
437 {
438 TCHAR* toolData = DBGetField(hResult, i, 1, NULL, 0);
439 TranslateStr(toolData, _T("\\\\"), _T("\\"));
440
441 DB_STATEMENT statment = DBPrepare(g_hCoreDB, _T("UPDATE object_tools SET tool_data=? WHERE tool_id=?"));
442 if (statment == NULL)
443 return FALSE;
444 DBBind(statment, 1, DB_SQLTYPE_TEXT, toolData, DB_BIND_DYNAMIC);
445 DBBind(statment, 2, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 0));
446 if(!DBExecute(statment))
447 return FALSE;
448 DBFreeStatement(statment);
449 }
450 DBFreeResult(hResult);
451 }
452
453 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='314' WHERE var_name='SchemaVersion'")));
454 return TRUE;
455}
456
457/**
458 * Upgrade from V312 to V313
459 */
460static BOOL H_UpgradeFromV312(int currVersion, int newVersion)
461{
462 CHK_EXEC(ConvertStrings(_T("object_tools"), _T("tool_id"), _T("tool_name")));
463 CHK_EXEC(ConvertStrings(_T("object_tools"), _T("tool_id"), _T("tool_data")));
464 CHK_EXEC(ConvertStrings(_T("object_tools"), _T("tool_id"), _T("description")));
465 CHK_EXEC(ConvertStrings(_T("object_tools"), _T("tool_id"), _T("confirmation_text")));
466 CHK_EXEC(ConvertStrings(_T("object_tools"), _T("tool_id"), _T("matching_oid")));
467 CHK_EXEC(ConvertStrings(_T("object_tools_table_columns"), _T("tool_id"), _T("col_number"), _T("col_name"), false));
468 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='313' WHERE var_name='SchemaVersion'")));
469 return TRUE;
470}
471
6498e05a
VK
472/**
473 * Upgrade from V311 to V312
474 */
475static BOOL H_UpgradeFromV311(int currVersion, int newVersion)
476{
477 CHK_EXEC(CreateConfigParam(_T("EnableReportingServer"), _T("0"), 1, 1));
478 CHK_EXEC(CreateConfigParam(_T("ReportingServerHostname"), _T("localhost"), 1, 1));
479 CHK_EXEC(CreateConfigParam(_T("ReportingServerPort"), _T("4710"), 1, 1));
480 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='312' WHERE var_name='SchemaVersion'")));
481 return TRUE;
482}
483
9262b092
VK
484/**
485 * Upgrade from V310 to V311
486 */
487static BOOL H_UpgradeFromV310(int currVersion, int newVersion)
488{
489 IntegerArray<UINT32> deleteList;
490
491 // reports
492 DB_RESULT hResult = SQLSelect(_T("SELECT id FROM reports"));
493 if (hResult != NULL)
494 {
495 int count = DBGetNumRows(hResult);
496 for(int i = 0; i < count; i++)
497 deleteList.add(DBGetFieldULong(hResult, i, 0));
498 DBFreeResult(hResult);
499 }
500
501 // report groups
502 hResult = SQLSelect(_T("SELECT id FROM containers WHERE object_class=25"));
503 if (hResult != NULL)
504 {
505 int count = DBGetNumRows(hResult);
506 for(int i = 0; i < count; i++)
507 deleteList.add(DBGetFieldULong(hResult, i, 0));
508 DBFreeResult(hResult);
509 }
510
511 for(int i = 0; i < deleteList.size(); i++)
512 {
513 TCHAR query[256];
514
515 _sntprintf(query, 256, _T("DELETE FROM object_properties WHERE object_id=%d"), deleteList.get(i));
516 CHK_EXEC(SQLQuery(query));
517
518 _sntprintf(query, 256, _T("DELETE FROM object_custom_attributes WHERE object_id=%d"), deleteList.get(i));
519 CHK_EXEC(SQLQuery(query));
520
521 _sntprintf(query, 256, _T("DELETE FROM acl WHERE object_id=%d"), deleteList.get(i));
522 CHK_EXEC(SQLQuery(query));
523
524 _sntprintf(query, 256, _T("DELETE FROM container_members WHERE object_id=%d OR container_id=%d"), deleteList.get(i), deleteList.get(i));
525 CHK_EXEC(SQLQuery(query));
526 }
527
528 static TCHAR batch[] =
529 _T("DROP TABLE reports\n")
530 _T("DROP TABLE report_results\n")
531 _T("DELETE FROM containers WHERE object_class=25\n")
532 _T("DELETE FROM object_properties WHERE object_id=8\n")
533 _T("<END>");
534 CHK_EXEC(SQLBatch(batch));
535 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='311' WHERE var_name='SchemaVersion'")));
536 return TRUE;
537}
538
32745683
VK
539/**
540 * Upgrade from V309 to V310
541 */
542static BOOL H_UpgradeFromV309(int currVersion, int newVersion)
543{
544 static TCHAR batch[] =
545 _T("ALTER TABLE interfaces ADD peer_proto integer\n")
546 _T("UPDATE interfaces SET peer_proto=0\n")
547 _T("<END>");
548 CHK_EXEC(SQLBatch(batch));
549 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='310' WHERE var_name='SchemaVersion'")));
550 return TRUE;
551}
552
34a320ad
VK
553/**
554 * Upgrade from V308 to V309
555 */
556static BOOL H_UpgradeFromV308(int currVersion, int newVersion)
557{
558 CHK_EXEC(CreateConfigParam(_T("HelpDeskLink"), _T("none"), 1, 1));
559 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='309' WHERE var_name='SchemaVersion'")));
560 return TRUE;
561}
562
2ab9314f 563/**
564 * Upgrade from V307 to V308
565 */
566static BOOL H_UpgradeFromV307(int currVersion, int newVersion)
567{
568 static TCHAR batch[] =
32745683
VK
569 _T("ALTER TABLE network_map_elements ADD flags integer\n")
570 _T("UPDATE network_map_elements SET flags=0\n") //set all elements like manually generated
571 _T("ALTER TABLE network_map_links ADD element_data $SQL:TEXT\n")
572 _T("ALTER TABLE network_map_links ADD flags integer\n")
573 _T("UPDATE network_map_links SET flags=0\n") //set all elements like manually generated
574 _T("<END>");
2ab9314f 575 CHK_EXEC(SQLBatch(batch));
576
32745683
VK
577 // it is assumed that now all autogenerated maps contain only autogenerated objects and links
578 // get elements from autogenerated maps and set their flags to AUTO_GENERATED for map elements and map links
2ab9314f 579 TCHAR query[256];
580 _sntprintf(query, 256, _T("SELECT id FROM network_maps WHERE map_type=%d OR map_type=%d"),
581 MAP_TYPE_LAYER2_TOPOLOGY, MAP_TYPE_IP_TOPOLOGY);
582 DB_RESULT hResult = SQLSelect(query);
583 if (hResult != NULL)
584 {
585 int count = DBGetNumRows(hResult);
586 for(int i = 0; i < count; i++)
587 {
588 _sntprintf(query, 256, _T("UPDATE network_map_elements SET flags='1' WHERE map_id=%d"),
589 DBGetFieldULong(hResult, i, 0));
590 CHK_EXEC(SQLQuery(query));
591 _sntprintf(query, 256, _T("UPDATE network_map_links SET flags='1' WHERE map_id=%d"),
592 DBGetFieldULong(hResult, i, 0));
593 CHK_EXEC(SQLQuery(query));
594 }
595 DBFreeResult(hResult);
596 }
597
598 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='308' WHERE var_name='SchemaVersion'")));
599 return TRUE;
600}
601
b3eb058b
VK
602/**
603 * Upgrade from V306 to V307
604 */
605static BOOL H_UpgradeFromV306(int currVersion, int newVersion)
606{
607 CHK_EXEC(SetColumnNullable(_T("config_clob"), _T("var_value")));
608 CHK_EXEC(ConvertStrings(_T("config_clob"), _T("var_name"), NULL, _T("var_value"), true));
609 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='307' WHERE var_name='SchemaVersion'")));
610 return TRUE;
611}
612
d1730ccf
VK
613/**
614 * Upgrade from V305 to V306
615 */
616static BOOL H_UpgradeFromV305(int currVersion, int newVersion)
617{
618 CHK_EXEC(CreateConfigParam(_T("ExtendedLogQueryAccessControl"), _T("0"), 1, 0));
619 CHK_EXEC(CreateConfigParam(_T("EnableTimedAlarmAck"), _T("1"), 1, 1));
9a1f7c45 620 CHK_EXEC(CreateConfigParam(_T("EnableCheckPointSNMP"), _T("0"), 1, 0));
d1730ccf
VK
621 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='306' WHERE var_name='SchemaVersion'")));
622 return TRUE;
623}
624
035745fc
VK
625/**
626 * Upgrade from V304 to V305
627 */
628static BOOL H_UpgradeFromV304(int currVersion, int newVersion)
629{
2ab9314f 630 CHK_EXEC(CreateEventTemplate(EVENT_IF_PEER_CHANGED, _T("SYS_IF_PEER_CHANGED"), SEVERITY_NORMAL, EF_LOG,
035745fc
VK
631 _T("New peer for interface %3 is %7 interface %10 (%12)"),
632 _T("Generated when peer information for interface changes.\r\n")
633 _T("Parameters:\r\n")
634 _T(" 1) Local interface object ID\r\n")
635 _T(" 2) Local interface index\r\n")
636 _T(" 3) Local interface name\r\n")
637 _T(" 4) Local interface IP address\r\n")
638 _T(" 5) Local interface MAC address\r\n")
639 _T(" 6) Peer node object ID\r\n")
640 _T(" 7) Peer node name\r\n")
641 _T(" 8) Peer interface object ID\r\n")
642 _T(" 9) Peer interface index\r\n")
643 _T(" 10) Peer interface name\r\n")
644 _T(" 11) Peer interface IP address\r\n")
645 _T(" 12) Peer interface MAC address")));
646 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='305' WHERE var_name='SchemaVersion'")));
647 return TRUE;
648}
649
fce4295c 650/**
651 * Upgrade from V303 to V304
652 */
653static BOOL H_UpgradeFromV303(int currVersion, int newVersion)
654{
d184506f 655 CHK_EXEC(CreateConfigParam(_T("StrictAlarmStatusFlow"), _T("0"), 1, 0));
fce4295c 656 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='304' WHERE var_name='SchemaVersion'")));
657 return TRUE;
658}
659
6f33021d 660/**
661 * Upgrade from V302 to V303
662 */
663static BOOL H_UpgradeFromV302(int currVersion, int newVersion)
664{
665 static TCHAR batch[] =
666 _T("ALTER TABLE alarms ADD ack_timeout integer\n")
667 _T("UPDATE alarms SET ack_timeout='0'\n")
668 _T("<END>");
669 CHK_EXEC(SQLBatch(batch));
670
671 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='303' WHERE var_name='SchemaVersion'")));
672 return TRUE;
673}
674
27088c41
AK
675/**
676 * Upgrade from V301 to V302
677 */
678static BOOL H_UpgradeFromV301(int currVersion, int newVersion)
679{
680 static TCHAR batch[] =
681 _T("DELETE FROM config WHERE var_name='DisableVacuum'\n")
682 _T("<END>");
683 CHK_EXEC(SQLBatch(batch));
684
685 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='302' WHERE var_name='SchemaVersion'")));
686 return TRUE;
687}
688
1d34c533
VK
689/**
690 * Upgrade from V300 to V301
691 */
692static BOOL H_UpgradeFromV300(int currVersion, int newVersion)
693{
694 static TCHAR batch[] =
695 _T("ALTER TABLE thresholds ADD script $SQL:TEXT\n")
696 _T("ALTER TABLE thresholds ADD sample_count integer\n")
697 _T("UPDATE thresholds SET sample_count=parameter_1\n")
698 _T("ALTER TABLE thresholds DROP COLUMN parameter_1\n")
699 _T("ALTER TABLE thresholds DROP COLUMN parameter_2\n")
700 _T("<END>");
701 CHK_EXEC(SQLBatch(batch));
702
703 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='301' WHERE var_name='SchemaVersion'")));
704 return TRUE;
705}
706
244c65ef
VK
707/**
708 * Upgrade from V299 to V300
709 */
710static BOOL H_UpgradeFromV299(int currVersion, int newVersion)
711{
712 CHK_EXEC(CreateConfigParam(_T("EnableXMPPConnector"), _T("0"), 1, 1));
713 CHK_EXEC(CreateConfigParam(_T("XMPPLogin"), _T("netxms@localhost"), 1, 1));
714 CHK_EXEC(CreateConfigParam(_T("XMPPPassword"), _T("netxms"), 1, 1));
715 CHK_EXEC(CreateConfigParam(_T("XMPPServer"), _T("localhost"), 1, 1));
716 CHK_EXEC(CreateConfigParam(_T("XMPPPort"), _T("5222"), 1, 1));
717
718 SetColumnNullable(_T("users"), _T("full_name"));
719 SetColumnNullable(_T("users"), _T("description"));
720 SetColumnNullable(_T("users"), _T("cert_mapping_data"));
721 SetColumnNullable(_T("user_groups"), _T("description"));
722 SetColumnNullable(_T("userdb_custom_attributes"), _T("attr_value"));
723
724 ConvertStrings(_T("users"), _T("id"), _T("full_name"));
725 ConvertStrings(_T("users"), _T("id"), _T("description"));
726 ConvertStrings(_T("users"), _T("id"), _T("cert_mapping_data"));
727 ConvertStrings(_T("user_groups"), _T("id"), _T("description"));
728 ConvertStrings(_T("userdb_custom_attributes"), _T("object_id"), _T("attr_name"), _T("attr_name"), true);
729 ConvertStrings(_T("userdb_custom_attributes"), _T("object_id"), _T("attr_name"), _T("attr_value"), true);
730
731 CHK_EXEC(SQLQuery(_T("ALTER TABLE users ADD xmpp_id varchar(127)")));
732
733 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='300' WHERE var_name='SchemaVersion'")));
734 return TRUE;
735}
736
ce47611c
VK
737/**
738 * Upgrade from V298 to V299
739 */
740static BOOL H_UpgradeFromV298(int currVersion, int newVersion)
741{
742 CHK_EXEC(SQLQuery(_T("UPDATE event_cfg SET message='Subnet %2 added',description='")
743 _T("Generated when subnet object added to the database.\r\n")
744 _T("Parameters:\r\n")
745 _T(" 1) Subnet object ID\r\n")
746 _T(" 2) Subnet name\r\n")
747 _T(" 3) IP address\r\n")
748 _T(" 4) Network mask")
749 _T("' WHERE event_code=2")));
750 CHK_EXEC(SQLQuery(_T("UPDATE event_cfg SET message='Subnet %2 deleted',description='")
751 _T("Generated when subnet object deleted from the database.\r\n")
752 _T("Parameters:\r\n")
753 _T(" 1) Subnet object ID\r\n")
754 _T(" 2) Subnet name\r\n")
755 _T(" 3) IP address\r\n")
756 _T(" 4) Network mask")
757 _T("' WHERE event_code=19")));
758 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='299' WHERE var_name='SchemaVersion'")));
759 return TRUE;
760}
761
af21affe
VK
762/**
763 * Upgrade from V297 to V298
764 */
765static BOOL H_UpgradeFromV297(int currVersion, int newVersion)
766{
767 CHK_EXEC(CreateConfigParam(_T("AgentDefaultSharedSecret"), _T("netxms"), 1, 0));
768 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='298' WHERE var_name='SchemaVersion'")));
769 return TRUE;
770}
771
e02953a4
VK
772/**
773 * Upgrade from V296 to V297
774 */
775static BOOL H_UpgradeFromV296(int currVersion, int newVersion)
776{
777 CHK_EXEC(CreateConfigParam(_T("UseSNMPTrapsForDiscovery"), _T("0"), 1, 1));
778 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='297' WHERE var_name='SchemaVersion'")));
779 return TRUE;
780}
781
71e4ed3a
VK
782/**
783 * Upgrade from V295 to V296
784 */
785static BOOL H_UpgradeFromV295(int currVersion, int newVersion)
786{
787 static TCHAR batch[] =
788 _T("ALTER TABLE nodes ADD boot_time integer\n")
789 _T("UPDATE nodes SET boot_time=0\n")
790 _T("<END>");
791 CHK_EXEC(SQLBatch(batch));
792
793 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='296' WHERE var_name='SchemaVersion'")));
794 return TRUE;
795}
796
c59466d2
VK
797/**
798 * Upgrade from V294 to V295
799 */
800static BOOL H_UpgradeFromV294(int currVersion, int newVersion)
801{
802 CHK_EXEC(CreateConfigParam(_T("IcmpPingTimeout"), _T("1500"), 1, 1));
803 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='295' WHERE var_name='SchemaVersion'")));
804 return TRUE;
805}
806
1d4f7890
VK
807/**
808 * Upgrade from V293 to V294
809 */
810static BOOL H_UpgradeFromV293(int currVersion, int newVersion)
811{
812 static TCHAR batch[] =
813 _T("DELETE FROM metadata WHERE var_name LIKE 'TDataTableCreationCommand_%'\n")
814 _T("INSERT INTO metadata (var_name,var_value)")
815 _T(" VALUES ('TDataTableCreationCommand_0','CREATE TABLE tdata_%d (item_id integer not null,tdata_timestamp integer not null,record_id $SQL:INT64 not null,UNIQUE(record_id))')\n")
816 _T("INSERT INTO metadata (var_name,var_value)")
817 _T(" VALUES ('TDataTableCreationCommand_1','CREATE TABLE tdata_records_%d (record_id $SQL:INT64 not null,row_id $SQL:INT64 not null,instance varchar(255) null,PRIMARY KEY(row_id),FOREIGN KEY (record_id) REFERENCES tdata_%d(record_id) ON DELETE CASCADE)')\n")
818 _T("INSERT INTO metadata (var_name,var_value)")
819 _T(" VALUES ('TDataTableCreationCommand_2','CREATE TABLE tdata_rows_%d (row_id $SQL:INT64 not null,column_id integer not null,value varchar(255) null,PRIMARY KEY(row_id,column_id),FOREIGN KEY (row_id) REFERENCES tdata_records_%d(row_id) ON DELETE CASCADE)')\n")
820 _T("<END>");
821 CHK_EXEC(SQLBatch(batch));
822
823 RecreateTData(_T("nodes"), true);
824 RecreateTData(_T("clusters"), true);
825 RecreateTData(_T("mobile_devices"), true);
826
827 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='294' WHERE var_name='SchemaVersion'")));
828 return TRUE;
829}
830
bc969eaf
VK
831/**
832 * Upgrade from V292 to V293
833 */
834static BOOL H_UpgradeFromV292(int currVersion, int newVersion)
835{
836 CHK_EXEC(CreateConfigParam(_T("DefaultConsoleShortTimeFormat"), _T("HH:mm"), 1, 0));
837 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='293' WHERE var_name='SchemaVersion'")));
838 return TRUE;
839}
840
badf9a95
VK
841/**
842 * Upgrade from V291 to V292
843 */
844static BOOL H_UpgradeFromV291(int currVersion, int newVersion)
845{
846 CHK_EXEC(SQLQuery(_T("ALTER TABLE event_policy ADD rule_guid varchar(36)")));
847
848 // Generate GUIDs for all objects
849 DB_RESULT hResult = SQLSelect(_T("SELECT rule_id FROM event_policy"));
850 if (hResult != NULL)
851 {
852 int count = DBGetNumRows(hResult);
853 for(int i = 0; i < count; i++)
854 {
855 uuid_t guid;
856 TCHAR query[256], buffer[64];
857
858 uuid_generate(guid);
859 _sntprintf(query, 256, _T("UPDATE event_policy SET rule_guid='%s' WHERE rule_id=%d"),
860 uuid_to_string(guid, buffer), DBGetFieldULong(hResult, i, 0));
861 CHK_EXEC(SQLQuery(query));
862 }
863 DBFreeResult(hResult);
864 }
865
866 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='292' WHERE var_name='SchemaVersion'")));
867 return TRUE;
868}
869
48d50116
VK
870/**
871 * Upgrade from V290 to V291
872 */
873static BOOL H_UpgradeFromV290(int currVersion, int newVersion)
874{
875 CHK_EXEC(SQLQuery(_T("UPDATE network_services SET service_type=7 WHERE service_type=6")));
876 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='291' WHERE var_name='SchemaVersion'")));
877 return TRUE;
878}
879
701726bc
VK
880/**
881 * Upgrade from V289 to V290
882 */
883static BOOL H_UpgradeFromV289(int currVersion, int newVersion)
884{
885 CHK_EXEC(SQLQuery(_T("ALTER TABLE network_maps ADD filter $SQL:TEXT")));
886 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='290' WHERE var_name='SchemaVersion'")));
887 return TRUE;
888}
889
90297892
VK
890/**
891 * Upgrade from V288 to V289
892 */
893static BOOL H_UpgradeFromV288(int currVersion, int newVersion)
894{
895 CHK_EXEC(SQLQuery(_T("ALTER TABLE dct_thresholds DROP COLUMN current_state")));
896 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='289' WHERE var_name='SchemaVersion'")));
897 return TRUE;
898}
899
a0dc14f9
VK
900/**
901 * Upgrade from V287 to V288
902 */
903static BOOL H_UpgradeFromV287(int currVersion, int newVersion)
904{
905 CHK_EXEC(CreateEventTemplate(EVENT_TABLE_THRESHOLD_ACTIVATED, _T("SYS_TABLE_THRESHOLD_ACTIVATED"), EVENT_SEVERITY_MINOR, EF_LOG,
906 _T("Threshold activated on table \"%2\" row %4 (%5)"),
907 _T("Generated when table threshold is activated.\r\n")
908 _T("Parameters:\r\n")
909 _T(" 1) Table DCI name\r\n")
910 _T(" 2) Table DCI description\r\n")
911 _T(" 3) Table DCI ID\r\n")
912 _T(" 4) Table row\r\n")
913 _T(" 5) Instance")));
914
915 CHK_EXEC(CreateEventTemplate(EVENT_TABLE_THRESHOLD_DEACTIVATED, _T("SYS_TABLE_THRESHOLD_DEACTIVATED"), EVENT_SEVERITY_NORMAL, EF_LOG,
916 _T("Threshold deactivated on table \"%2\" row %4 (%5)"),
917 _T("Generated when table threshold is deactivated.\r\n")
918 _T("Parameters:\r\n")
919 _T(" 1) Table DCI name\r\n")
920 _T(" 2) Table DCI description\r\n")
921 _T(" 3) Table DCI ID\r\n")
922 _T(" 4) Table row\r\n")
923 _T(" 5) Instance")));
924
925 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='288' WHERE var_name='SchemaVersion'")));
926 return TRUE;
927}
928
9387bc59
VK
929/**
930 * Upgrade from V286 to V287
931 */
932static BOOL H_UpgradeFromV286(int currVersion, int newVersion)
933{
934 static TCHAR batch[] =
935 _T("ALTER TABLE dc_table_columns ADD sequence_number integer\n")
936 _T("UPDATE dc_table_columns SET sequence_number=0\n")
937 _T("<END>");
938 CHK_EXEC(SQLBatch(batch));
939
940 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='287' WHERE var_name='SchemaVersion'")));
941 return TRUE;
942}
943
9098ad59
VK
944/**
945 * Upgrade from V285 to V286
946 */
947static BOOL H_UpgradeFromV285(int currVersion, int newVersion)
948{
949 CHK_EXEC(CreateTable(
950 _T("CREATE TABLE dct_thresholds (")
951 _T("id integer not null,")
952 _T("table_id integer not null,")
953 _T("sequence_number integer not null,")
954 _T("current_state char(1) not null,")
955 _T("activation_event integer not null,")
956 _T("deactivation_event integer not null,")
957 _T("PRIMARY KEY(id))")));
958
959 CHK_EXEC(CreateTable(
960 _T("CREATE TABLE dct_threshold_conditions (")
961 _T("threshold_id integer not null,")
962 _T("group_id integer not null,")
963 _T("sequence_number integer not null,")
964 _T("column_name varchar(63) null,")
965 _T("check_operation integer not null,")
966 _T("check_value varchar(255) null,")
967 _T("PRIMARY KEY(threshold_id,group_id,sequence_number))")));
968
969 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='286' WHERE var_name='SchemaVersion'")));
970 return TRUE;
971}
972
17017844
VK
973/**
974 * Upgrade from V284 to V285
975 */
976static BOOL H_UpgradeFromV284(int currVersion, int newVersion)
977{
978 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_items_node_id ON items(node_id)")));
979 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_dc_tables_node_id ON dc_tables(node_id)")));
980
981 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='285' WHERE var_name='SchemaVersion'")));
982 return TRUE;
983}
984
eb4822b6
VK
985/**
986 * Upgrade from V283 to V284
987 */
988static BOOL H_UpgradeFromV283(int currVersion, int newVersion)
989{
990 CHK_EXEC(CreateConfigParam(_T("SNMPTrapPort"), _T("162"), 1, 1));
991
992 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='284' WHERE var_name='SchemaVersion'")));
993 return TRUE;
994}
995
0b77b73e
VK
996/**
997 * Upgrade from V282 to V283
998 */
999static BOOL H_UpgradeFromV282(int currVersion, int newVersion)
1000{
1001 static TCHAR batch[] =
1002 _T("ALTER TABLE dc_table_columns ADD display_name varchar(255)\n")
1003 _T("UPDATE dc_table_columns SET display_name=column_name\n")
1004 _T("<END>");
1005 CHK_EXEC(SQLBatch(batch));
1006
1007 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='283' WHERE var_name='SchemaVersion'")));
1008 return TRUE;
1009}
1010
549f48b3
VK
1011/**
1012 * Upgrade from V281 to V282
1013 */
1014static BOOL H_UpgradeFromV281(int currVersion, int newVersion)
1015{
1016 CHK_EXEC(SQLQuery(_T("DELETE FROM config WHERE var_name='WindowsConsoleUpgradeURL'")));
1017 CHK_EXEC(CreateConfigParam(_T("EnableObjectTransactions"), _T("0"), 1, 1));
1018
1019 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='282' WHERE var_name='SchemaVersion'")));
1020 return TRUE;
1021}
1022
22aaa779
VK
1023/**
1024 * Upgrade from V280 to V281
1025 */
1026static BOOL H_UpgradeFromV280(int currVersion, int newVersion)
1027{
1028 static TCHAR batch[] =
1029 _T("DELETE FROM metadata WHERE var_name='TDataTableCreationCommand'\n")
1030 _T("INSERT INTO metadata (var_name,var_value)")
1031 _T(" VALUES ('TDataTableCreationCommand_0','CREATE TABLE tdata_%d (item_id integer not null,tdata_timestamp integer not null,record_id $SQL:INT64 not null)')\n")
1032 _T("INSERT INTO metadata (var_name,var_value)")
1033 _T(" VALUES ('TDataTableCreationCommand_1','CREATE TABLE tdata_records_%d (record_id $SQL:INT64 not null,row_id $SQL:INT64 not null,instance varchar(255) null,PRIMARY KEY(record_id,row_id))')\n")
1034 _T("INSERT INTO metadata (var_name,var_value)")
1035 _T(" VALUES ('TDataTableCreationCommand_2','CREATE TABLE tdata_rows_%d (row_id $SQL:INT64 not null,column_id integer not null,value varchar(255) null,PRIMARY KEY(row_id,column_id))')\n")
1036 _T("INSERT INTO metadata (var_name,var_value)")
1037 _T(" VALUES ('TDataIndexCreationCommand_1','CREATE INDEX idx_tdata_rec_%d_instance ON tdata_records_%d(instance)')\n")
1038 _T("<END>");
1039 CHK_EXEC(SQLBatch(batch));
1040
1d4f7890
VK
1041 RecreateTData(_T("nodes"), false);
1042 RecreateTData(_T("clusters"), false);
1043 RecreateTData(_T("mobile_devices"), false);
22aaa779
VK
1044
1045 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='281' WHERE var_name='SchemaVersion'")));
1046 return TRUE;
1047}
1048
1049/**
1050 * Upgrade from V279 to V280
1051 */
1052static BOOL H_UpgradeFromV279(int currVersion, int newVersion)
1053{
1054 static TCHAR batch[] =
1055 _T("ALTER TABLE dc_table_columns ADD flags integer\n")
1056 _T("UPDATE dc_table_columns SET flags=data_type\n")
1057 _T("ALTER TABLE dc_table_columns DROP COLUMN data_type\n")
1058 _T("<END>");
1059 CHK_EXEC(SQLBatch(batch));
1060
1061 DB_RESULT hResult = SQLSelect(_T("SELECT item_id,instance_column FROM dc_tables"));
1062 if (hResult != NULL)
1063 {
1064 int count = DBGetNumRows(hResult);
1065 for(int i = 0; i < count; i++)
1066 {
1067 TCHAR columnName[MAX_COLUMN_NAME] = _T("");
1068 DBGetField(hResult, i, 1, columnName, MAX_COLUMN_NAME);
1069 if (columnName[0] != 0)
1070 {
1071 TCHAR query[256];
1072 _sntprintf(query, 256, _T("UPDATE dc_table_columns SET flags=flags+256 WHERE table_id=%d AND column_name=%s"),
1073 DBGetFieldLong(hResult, i, 0), (const TCHAR *)DBPrepareString(g_hCoreDB, columnName));
1074 CHK_EXEC(SQLQuery(query));
1075 }
1076 }
1077 DBFreeResult(hResult);
1078 }
1079 else
1080 {
1081 if (!g_bIgnoreErrors)
1082 return FALSE;
1083 }
1084
1085 CHK_EXEC(SQLQuery(_T("ALTER TABLE dc_tables DROP COLUMN instance_column")));
1086
1087 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='280' WHERE var_name='SchemaVersion'")));
1088 return TRUE;
1089}
1090
22ee6d97
VK
1091/**
1092 * Upgrade from V278 to V279
1093 */
1094static BOOL H_UpgradeFromV278(int currVersion, int newVersion)
1095{
1096 CHK_EXEC(CreateConfigParam(_T("DeleteEventsOfDeletedObject"), _T("1"), 1, 0));
1097 CHK_EXEC(CreateConfigParam(_T("DeleteAlarmsOfDeletedObject"), _T("1"), 1, 0));
1098
1099 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='279' WHERE var_name='SchemaVersion'")));
1100 return TRUE;
1101}
1102
85ae39bc
VK
1103/**
1104 * Upgrade from V277 to V278
1105 */
1106static BOOL H_UpgradeFromV277(int currVersion, int newVersion)
1107{
1108 DB_RESULT hResult = SQLSelect(_T("SELECT id FROM clusters"));
1109 if (hResult != NULL)
1110 {
1111 int count = DBGetNumRows(hResult);
1112 for(int i = 0; i < count; i++)
1113 {
1114 DWORD id = DBGetFieldULong(hResult, i, 0);
1115 if (!CreateIDataTable(id))
1116 {
1117 if (!g_bIgnoreErrors)
1118 {
1119 DBFreeResult(hResult);
1120 return FALSE;
1121 }
1122 }
22aaa779 1123 if (!CreateTDataTable_preV281(id))
85ae39bc
VK
1124 {
1125 if (!g_bIgnoreErrors)
1126 {
1127 DBFreeResult(hResult);
1128 return FALSE;
1129 }
1130 }
1131 }
1132 DBFreeResult(hResult);
1133 }
1134 else
1135 {
1136 if (!g_bIgnoreErrors)
1137 return FALSE;
1138 }
1139
1140 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='278' WHERE var_name='SchemaVersion'")));
1141 return TRUE;
1142}
1143
62f41164
VK
1144/**
1145 * Upgrade from V276 to V277
1146 */
1147static BOOL H_UpgradeFromV276(int currVersion, int newVersion)
1148{
b4c2a628
VK
1149 CHK_EXEC(CreateTable(_T("CREATE TABLE dci_summary_tables (")
1150 _T("id integer not null,")
1151 _T("menu_path varchar(255) not null,")
1152 _T("title varchar(127) null,")
1153 _T("node_filter $SQL:TEXT null,")
1154 _T("flags integer not null,")
1155 _T("columns $SQL:TEXT null,")
1156 _T("PRIMARY KEY(id))")));
1157
62f41164
VK
1158 CHK_EXEC(CreateConfigParam(_T("DefaultMapBackgroundColor"), _T("0xffffff"), 1, 0));
1159
1160 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='277' WHERE var_name='SchemaVersion'")));
1161 return TRUE;
1162}
1163
55bdca5a
VK
1164/**
1165 * Upgrade from V275 to V276
1166 */
1167static BOOL H_UpgradeFromV275(int currVersion, int newVersion)
1168{
1169 static TCHAR batch[] =
1170 _T("ALTER TABLE dc_table_columns DROP COLUMN transformation_script\n")
1171 _T("ALTER TABLE dc_tables ADD transformation_script $SQL:TEXT\n")
1172 _T("<END>");
1173 CHK_EXEC(SQLBatch(batch));
1174
1175 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='276' WHERE var_name='SchemaVersion'")));
1176 return TRUE;
1177}
1178
8715a84c
VK
1179/**
1180 * Upgrade from V274 to V275
1181 */
1182static BOOL H_UpgradeFromV274(int currVersion, int newVersion)
1183{
1184 static TCHAR batch[] =
1185 _T("ALTER TABLE nodes ADD rack_image varchar(36)\n")
1186 _T("ALTER TABLE nodes ADD rack_position integer\n")
1187 _T("ALTER TABLE nodes ADD rack_id integer\n")
1188 _T("UPDATE nodes SET rack_image='00000000-0000-0000-0000-000000000000',rack_position=0,rack_id=0\n")
1189 _T("<END>");
1190 CHK_EXEC(SQLBatch(batch));
1191
1192 CHK_EXEC(CreateTable(_T("CREATE TABLE access_points (")
1193 _T("id integer not null,")
1194 _T("node_id integer not null,")
f1989a3a 1195 _T("mac_address varchar(12) null,")
8715a84c
VK
1196 _T("vendor varchar(64) null,")
1197 _T("model varchar(128) null,")
1198 _T("serial_number varchar(64) null,")
1199 _T("PRIMARY KEY(id))")));
1200
1201 CHK_EXEC(CreateTable(_T("CREATE TABLE racks (")
1202 _T("id integer not null,")
1203 _T("height integer not null,")
1204 _T("PRIMARY KEY(id))")));
1205
1206 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='275' WHERE var_name='SchemaVersion'")));
1207 return TRUE;
1208}
1209
d02f6b92
VK
1210/**
1211 * Upgrade from V273 to V274
1212 */
1213static BOOL H_UpgradeFromV273(int currVersion, int newVersion)
1214{
1215 static TCHAR batch[] =
1216 _T("ALTER TABLE items ADD samples integer\n")
1217 _T("UPDATE items SET samples=0\n")
1218 _T("<END>");
1219 CHK_EXEC(SQLBatch(batch));
1220
1221 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='274' WHERE var_name='SchemaVersion'")));
1222 return TRUE;
1223}
1224
f05a8a45
VK
1225/**
1226 * Upgrade from V272 to V273
1227 */
1228static BOOL H_UpgradeFromV272(int currVersion, int newVersion)
1229{
1230 CHK_EXEC(CreateConfigParam(_T("DefaultDCIRetentionTime"), _T("30"), 1, 0));
1231 CHK_EXEC(CreateConfigParam(_T("DefaultDCIPollingInterval"), _T("60"), 1, 0));
1232 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='273' WHERE var_name='SchemaVersion'")));
1233 return TRUE;
1234}
1235
0f75f8fc
VK
1236/**
1237 * Upgrade from V271 to V272
1238 */
1239static BOOL H_UpgradeFromV271(int currVersion, int newVersion)
1240{
1241 CHK_EXEC(CreateConfigParam(_T("SNMPTrapLogRetentionTime"), _T("90"), 1, 0));
28e1575f 1242 CHK_EXEC(SQLQuery(_T("ALTER TABLE nodes ADD driver_name varchar(32)\n")));
0f75f8fc
VK
1243 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='272' WHERE var_name='SchemaVersion'")));
1244 return TRUE;
1245}
1246
86634c2c
VK
1247/**
1248 * Upgrade from V270 to V271
1249 */
1250static BOOL H_UpgradeFromV270(int currVersion, int newVersion)
1251{
1252 static TCHAR batch[] =
1253 _T("ALTER TABLE object_properties ADD location_accuracy integer\n")
f2d5b2c4
VK
1254 _T("ALTER TABLE object_properties ADD location_timestamp integer\n")
1255 _T("UPDATE object_properties SET location_accuracy=0,location_timestamp=0\n")
86634c2c
VK
1256 _T("<END>");
1257 CHK_EXEC(SQLBatch(batch));
1258
1259 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='271' WHERE var_name='SchemaVersion'")));
1260 return TRUE;
1261}
1262
afbe5388
VK
1263/**
1264 * Upgrade from V269 to V270
1265 */
1266static BOOL H_UpgradeFromV269(int currVersion, int newVersion)
1267{
6f33021d 1268 static TCHAR batch[] =
afbe5388
VK
1269 _T("ALTER TABLE items ADD instd_method integer\n")
1270 _T("ALTER TABLE items ADD instd_data varchar(255)\n")
1271 _T("ALTER TABLE items ADD instd_filter $SQL:TEXT\n")
1272 _T("UPDATE items SET instd_method=0\n")
1273 _T("<END>");
1274 CHK_EXEC(SQLBatch(batch));
1275
1276 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='270' WHERE var_name='SchemaVersion'")));
1277 return TRUE;
1278}
1279
480e036b
VK
1280/**
1281 * Upgrade from V268 to V269
1282 */
1283static BOOL H_UpgradeFromV268(int currVersion, int newVersion)
1284{
1285 CHK_EXEC(ResizeColumn(_T("alarms"), _T("message"), 2000));
1286 CHK_EXEC(ResizeColumn(_T("alarm_events"), _T("message"), 2000));
1287 CHK_EXEC(ResizeColumn(_T("event_log"), _T("event_message"), 2000));
1288 CHK_EXEC(ResizeColumn(_T("event_cfg"), _T("message"), 2000));
1289 CHK_EXEC(ResizeColumn(_T("event_policy"), _T("alarm_message"), 2000));
1290 CHK_EXEC(ResizeColumn(_T("items"), _T("name"), 1024));
1291 CHK_EXEC(ResizeColumn(_T("dc_tables"), _T("name"), 1024));
1292
1293 CHK_EXEC(SetColumnNullable(_T("event_policy"), _T("alarm_key")));
1294 CHK_EXEC(SetColumnNullable(_T("event_policy"), _T("alarm_message")));
1295 CHK_EXEC(SetColumnNullable(_T("event_policy"), _T("comments")));
1296 CHK_EXEC(SetColumnNullable(_T("event_policy"), _T("situation_instance")));
1297 CHK_EXEC(SetColumnNullable(_T("event_policy"), _T("script")));
1298 CHK_EXEC(ConvertStrings(_T("event_policy"), _T("rule_id"), _T("alarm_key")));
1299 CHK_EXEC(ConvertStrings(_T("event_policy"), _T("rule_id"), _T("alarm_message")));
1300 CHK_EXEC(ConvertStrings(_T("event_policy"), _T("rule_id"), _T("comments")));
1301 CHK_EXEC(ConvertStrings(_T("event_policy"), _T("rule_id"), _T("situation_instance")));
1302 CHK_EXEC(ConvertStrings(_T("event_policy"), _T("rule_id"), _T("script")));
1303
1304 CHK_EXEC(SetColumnNullable(_T("policy_situation_attr_list"), _T("attr_value")));
1305 // convert strings in policy_situation_attr_list
1306 DB_RESULT hResult = SQLSelect(_T("SELECT rule_id,situation_id,attr_name,attr_value FROM policy_situation_attr_list"));
1307 if (hResult != NULL)
1308 {
1309 if (SQLQuery(_T("DELETE FROM policy_situation_attr_list")))
1310 {
1311 TCHAR name[MAX_DB_STRING], value[MAX_DB_STRING], query[1024];
1312 int count = DBGetNumRows(hResult);
1313 for(int i = 0; i < count; i++)
1314 {
1315 LONG ruleId = DBGetFieldLong(hResult, i, 0);
1316 LONG situationId = DBGetFieldLong(hResult, i, 1);
1317 DBGetField(hResult, i, 2, name, MAX_DB_STRING);
1318 DBGetField(hResult, i, 3, value, MAX_DB_STRING);
1319
1320 DecodeSQLString(name);
1321 DecodeSQLString(value);
1322
1323 if (name[0] == 0)
1324 _tcscpy(name, _T("noname"));
1325
1326 _sntprintf(query, 1024, _T("INSERT INTO policy_situation_attr_list (rule_id,situation_id,attr_name,attr_value) VALUES (%d,%d,%s,%s)"),
1327 ruleId, situationId, (const TCHAR *)DBPrepareString(g_hCoreDB, name), (const TCHAR *)DBPrepareString(g_hCoreDB, value));
1328 if (!SQLQuery(query))
1329 {
1330 if (!g_bIgnoreErrors)
1331 {
1332 DBFreeResult(hResult);
1333 return FALSE;
1334 }
1335 }
1336 }
1337 }
1338 else
1339 {
1340 if (!g_bIgnoreErrors)
1341 {
1342 DBFreeResult(hResult);
1343 return FALSE;
1344 }
1345 }
1346 DBFreeResult(hResult);
1347 }
1348 else
1349 {
1350 if (!g_bIgnoreErrors)
1351 return FALSE;
1352 }
1353
1354 CHK_EXEC(SetColumnNullable(_T("event_cfg"), _T("description")));
1355 CHK_EXEC(SetColumnNullable(_T("event_cfg"), _T("message")));
1356 CHK_EXEC(ConvertStrings(_T("event_cfg"), _T("event_code"), _T("description")));
1357 CHK_EXEC(ConvertStrings(_T("event_cfg"), _T("event_code"), _T("message")));
1358
1359 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='269' WHERE var_name='SchemaVersion'")));
1360 return TRUE;
1361}
1362
d6bf58f9
VK
1363/**
1364 * Upgrade from V267 to V268
1365 */
1366static BOOL H_UpgradeFromV267(int currVersion, int newVersion)
1367{
480e036b
VK
1368 CHK_EXEC(SetColumnNullable(_T("network_services"), _T("check_request")));
1369 CHK_EXEC(SetColumnNullable(_T("network_services"), _T("check_responce")));
d6bf58f9
VK
1370 CHK_EXEC(ConvertStrings(_T("network_services"), _T("id"), _T("check_request")));
1371 CHK_EXEC(ConvertStrings(_T("network_services"), _T("id"), _T("check_responce")));
1372
480e036b 1373 CHK_EXEC(SetColumnNullable(_T("config"), _T("var_value")));
d6bf58f9
VK
1374 CHK_EXEC(ConvertStrings(_T("config"), _T("var_name"), NULL, _T("var_value"), true));
1375
480e036b 1376 CHK_EXEC(SetColumnNullable(_T("dci_schedules"), _T("schedule")));
d6bf58f9
VK
1377 CHK_EXEC(ConvertStrings(_T("dci_schedules"), _T("schedule_id"), _T("item_id"), _T("schedule"), false));
1378
1379 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='268' WHERE var_name='SchemaVersion'")));
1380 return TRUE;
1381}
1382
c1482463
VK
1383/**
1384 * Upgrade from V266 to V267
1385 */
1386static BOOL H_UpgradeFromV266(int currVersion, int newVersion)
1387{
1388 CHK_EXEC(CreateEventTemplate(EVENT_NODE_UNREACHABLE, _T("SYS_NODE_UNREACHABLE"), EVENT_SEVERITY_CRITICAL,
1389 EF_LOG, _T("Node unreachable because of network failure"),
1390 _T("Generated when node is unreachable by management server because of network failure.\r\nParameters:\r\n No event-specific parameters")));
1391 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='267' WHERE var_name='SchemaVersion'")));
1392 return TRUE;
1393}
1394
69bb7f47
VK
1395/**
1396 * Upgrade from V265 to V266
1397 */
1398static BOOL H_UpgradeFromV265(int currVersion, int newVersion)
1399{
1400 // create index on root event ID in event log
1401 switch(g_iSyntax)
1402 {
1403 case DB_SYNTAX_MSSQL:
1404 case DB_SYNTAX_PGSQL:
1405 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_event_log_root_id ON event_log(root_event_id) WHERE root_event_id > 0")));
1406 break;
1407 case DB_SYNTAX_ORACLE:
1408 CHK_EXEC(SQLQuery(_T("CREATE OR REPLACE FUNCTION zero_to_null(id NUMBER) ")
1409 _T("RETURN NUMBER ")
1410 _T("DETERMINISTIC ")
1411 _T("AS BEGIN")
1412 _T(" IF id > 0 THEN")
1413 _T(" RETURN id;")
1414 _T(" ELSE")
1415 _T(" RETURN NULL;")
1416 _T(" END IF;")
1417 _T("END;")));
1418 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_event_log_root_id ON event_log(zero_to_null(root_event_id))")));
1419 break;
1420 default:
1421 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_event_log_root_id ON event_log(root_event_id)")));
1422 break;
1423 }
1424
1425 CHK_EXEC(CreateTable(_T("CREATE TABLE mapping_tables (")
1426 _T("id integer not null,")
1427 _T("name varchar(63) not null,")
1428 _T("flags integer not null,")
1429 _T("description $SQL:TXT4K null,")
1430 _T("PRIMARY KEY(id))")));
1431
1432 CHK_EXEC(CreateTable(_T("CREATE TABLE mapping_data (")
1433 _T("table_id integer not null,")
1434 _T("md_key varchar(63) not null,")
1435 _T("md_value varchar(255) null,")
f41af2c4 1436 _T("description $SQL:TXT4K null,")
69bb7f47
VK
1437 _T("PRIMARY KEY(table_id,md_key))")));
1438
1439 CHK_EXEC(SQLQuery(_T("DROP TABLE deleted_objects")));
1440
1441 CHK_EXEC(CreateConfigParam(_T("FirstFreeObjectId"), _T("100"), 0, 1, FALSE));
1442
1443 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='266' WHERE var_name='SchemaVersion'")));
1444 return TRUE;
1445}
1446
b1e9b6b3
VK
1447/**
1448 * Upgrade from V264 to V265
1449 */
1450static BOOL H_UpgradeFromV264(int currVersion, int newVersion)
1451{
1452 CHK_EXEC(CreateTable(_T("CREATE TABLE alarm_events (")
1453 _T("alarm_id integer not null,")
1454 _T("event_id $SQL:INT64 not null,")
1455 _T("event_code integer not null,")
1456 _T("event_name varchar(63) null,")
1457 _T("severity integer not null,")
1458 _T("source_object_id integer not null,")
1459 _T("event_timestamp integer not null,")
1460 _T("message varchar(255) null,")
1461 _T("PRIMARY KEY(alarm_id,event_id))")));
1462 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_alarm_events_alarm_id ON alarm_events(alarm_id)")));
1463 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='265' WHERE var_name='SchemaVersion'")));
1464 return TRUE;
1465}
1466
9aa67910
VK
1467/**
1468 * Upgrade from V263 to V264
1469 */
1470static BOOL H_UpgradeFromV263(int currVersion, int newVersion)
1471{
1472 CHK_EXEC(CreateTable(_T("CREATE TABLE mobile_devices (")
1473 _T("id integer not null,")
1474 _T("device_id varchar(64) not null,")
1475 _T("vendor varchar(64) null,")
1476 _T("model varchar(128) null,")
1477 _T("serial_number varchar(64) null,")
1478 _T("os_name varchar(32) null,")
1479 _T("os_version varchar(64) null,")
1480 _T("user_id varchar(64) null,")
171c2fd6 1481 _T("battery_level integer not null,")
9aa67910 1482 _T("PRIMARY KEY(id))")));
534e1b83 1483 CHK_EXEC(CreateConfigParam(_T("MobileDeviceListenerPort"), _T("4747"), 1, 1));
9aa67910
VK
1484 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='264' WHERE var_name='SchemaVersion'")));
1485 return TRUE;
1486}
1487
84880c89
VK
1488/**
1489 * Upgrade from V262 to V263
1490 */
1491static BOOL H_UpgradeFromV262(int currVersion, int newVersion)
1492{
1493 CHK_EXEC(SQLQuery(_T("ALTER TABLE network_maps ADD radius integer")));
1494 CHK_EXEC(SQLQuery(_T("UPDATE network_maps SET radius=-1")));
1495 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='263' WHERE var_name='SchemaVersion'")));
1496 return TRUE;
1497}
1498
dc4a1aec
AK
1499/**
1500 * Upgrade from V261 to V262
1501 */
1502static BOOL H_UpgradeFromV261(int currVersion, int newVersion)
1503{
534e1b83 1504 CHK_EXEC(CreateConfigParam(_T("ApplyDCIFromTemplateToDisabledDCI"), _T("0"), 1, 1));
dc4a1aec
AK
1505 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='262' WHERE var_name='SchemaVersion'")));
1506 return TRUE;
1507}
1508
4f50e45c
VK
1509/**
1510 * Upgrade from V260 to V261
1511 */
1512static BOOL H_UpgradeFromV260(int currVersion, int newVersion)
1513{
534e1b83 1514 CHK_EXEC(CreateConfigParam(_T("NumberOfBusinessServicePollers"), _T("10"), 1, 1));
4f50e45c
VK
1515 CHK_EXEC(SQLQuery(_T("DELETE FROM config WHERE var_name='NumberOfEventProcessors'")));
1516 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='261' WHERE var_name='SchemaVersion'")));
1517 return TRUE;
1518}
a203ea53 1519
4f50e45c
VK
1520/**
1521 * Upgrade from V259 to V260
1522 */
a203ea53
AK
1523static BOOL H_UpgradeFromV259(int currVersion, int newVersion)
1524{
534e1b83 1525 CHK_EXEC(CreateConfigParam(_T("UseFQDNForNodeNames"), _T("1"), 1, 1));
a203ea53
AK
1526 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='260' WHERE var_name='SchemaVersion'")));
1527 return TRUE;
1528}
1529
4f50e45c
VK
1530/**
1531 * Upgrade from V258 to V259
1532 */
5da6ca46
VK
1533static BOOL H_UpgradeFromV258(int currVersion, int newVersion)
1534{
1535 // have to made these columns nullable again because
1536 // because they was forgotten as NOT NULL in schema.in
1537 // and so some databases can still have them as NOT NULL
480e036b
VK
1538 CHK_EXEC(SetColumnNullable(_T("templates"), _T("apply_filter")));
1539 CHK_EXEC(SetColumnNullable(_T("containers"), _T("auto_bind_filter")));
5da6ca46
VK
1540
1541 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='259' WHERE var_name='SchemaVersion'")));
1542 return TRUE;
1543}
1544
4f50e45c
VK
1545/**
1546 * Upgrade from V257 to V258
1547 */
dd42ad0a
AK
1548static BOOL H_UpgradeFromV257(int currVersion, int newVersion)
1549{
6f33021d 1550 static TCHAR batch[] =
dd42ad0a
AK
1551 _T("ALTER TABLE nodes ADD down_since integer\n")
1552 _T("UPDATE nodes SET down_since=0\n")
1553 _T("<END>");
1554
1555 CHK_EXEC(SQLBatch(batch));
1556
534e1b83 1557 CHK_EXEC(CreateConfigParam(_T("DeleteUnreachableNodesPeriod"), _T("0"), 1, 1));
dd42ad0a
AK
1558
1559 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='258' WHERE var_name='SchemaVersion'")));
1560 return TRUE;
1561}
aa16f82b 1562
534e1b83
VK
1563/**
1564 * Upgrade from V256 to V257
1565 */
e4acd770
VK
1566static BOOL H_UpgradeFromV256(int currVersion, int newVersion)
1567{
6f33021d 1568 static TCHAR batch[] =
e4acd770
VK
1569 _T("ALTER TABLE network_maps ADD bg_color integer\n")
1570 _T("ALTER TABLE network_maps ADD link_routing integer\n")
1571 _T("UPDATE network_maps SET bg_color=16777215,link_routing=1\n")
1572 _T("ALTER TABLE network_map_links ADD routing integer\n")
1573 _T("ALTER TABLE network_map_links ADD bend_points $SQL:TXT4K\n")
1574 _T("UPDATE network_map_links SET routing=0\n")
1575 _T("<END>");
1576
1577 CHK_EXEC(SQLBatch(batch));
6f33021d 1578
e4acd770
VK
1579 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='257' WHERE var_name='SchemaVersion'")));
1580 return TRUE;
1581}
1582
534e1b83
VK
1583/**
1584 * Upgrade from V255 to V256
1585 */
aabe5b72
VK
1586static BOOL H_UpgradeFromV255(int currVersion, int newVersion)
1587{
534e1b83
VK
1588 CHK_EXEC(CreateConfigParam(_T("DefaultConsoleDateFormat"), _T("dd.MM.yyyy"), 1, 0));
1589 CHK_EXEC(CreateConfigParam(_T("DefaultConsoleTimeFormat"), _T("HH:mm:ss"), 1, 0));
aabe5b72
VK
1590
1591 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='256' WHERE var_name='SchemaVersion'")));
1592 return TRUE;
1593}
1594
480e036b
VK
1595/**
1596 * Upgrade from V254 to V255
1597 */
5f6bc78c
VK
1598static BOOL H_UpgradeFromV254(int currVersion, int newVersion)
1599{
6f33021d 1600 static TCHAR batch[] =
5f6bc78c
VK
1601 _T("ALTER TABLE alarms ADD resolved_by integer\n")
1602 _T("UPDATE alarms SET resolved_by=0\n")
1603 _T("UPDATE alarms SET alarm_state=3 WHERE alarm_state=2\n")
1604 _T("<END>");
1605
1606 CHK_EXEC(SQLBatch(batch));
1607
3e9e0cc5 1608 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='255' WHERE var_name='SchemaVersion'")));
5f6bc78c
VK
1609 return TRUE;
1610}
40647141 1611
badf9a95
VK
1612/**
1613 * Upgrade from V253 to V254
1614 */
40647141
VK
1615static BOOL H_UpgradeFromV253(int currVersion, int newVersion)
1616{
6f33021d 1617 static TCHAR batch[] =
40647141
VK
1618 _T("ALTER TABLE network_maps ADD flags integer\n")
1619 _T("ALTER TABLE network_maps ADD link_color integer\n")
1620 _T("UPDATE network_maps SET flags=1,link_color=-1\n")
1621 _T("ALTER TABLE network_map_links ADD color integer\n")
1622 _T("ALTER TABLE network_map_links ADD status_object integer\n")
1623 _T("UPDATE network_map_links SET color=-1,status_object=0\n")
1624 _T("<END>");
1625
1626 CHK_EXEC(SQLBatch(batch));
1627
1628 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='254' WHERE var_name='SchemaVersion'")));
1629 return TRUE;
1630}
1631
d6bf58f9
VK
1632/**
1633 * Upgrade from V252 to V253
1634 */
feab3324
VK
1635static BOOL H_UpgradeFromV252(int currVersion, int newVersion)
1636{
480e036b 1637 CHK_EXEC(SetColumnNullable(_T("templates"), _T("apply_filter")));
242e9c7f
VK
1638 CHK_EXEC(ConvertStrings(_T("templates"), _T("id"), _T("apply_filter")));
1639
480e036b 1640 CHK_EXEC(SetColumnNullable(_T("containers"), _T("auto_bind_filter")));
242e9c7f
VK
1641 CHK_EXEC(ConvertStrings(_T("containers"), _T("id"), _T("auto_bind_filter")));
1642
6f33021d 1643 static TCHAR batch[] =
feab3324 1644 _T("ALTER TABLE templates ADD flags integer\n")
2984ac95
VK
1645 _T("UPDATE templates SET flags=0 WHERE enable_auto_apply=0\n")
1646 _T("UPDATE templates SET flags=3 WHERE enable_auto_apply<>0\n")
feab3324
VK
1647 _T("ALTER TABLE templates DROP COLUMN enable_auto_apply\n")
1648 _T("ALTER TABLE containers ADD flags integer\n")
2984ac95
VK
1649 _T("UPDATE containers SET flags=0 WHERE enable_auto_bind=0\n")
1650 _T("UPDATE containers SET flags=3 WHERE enable_auto_bind<>0\n")
feab3324
VK
1651 _T("ALTER TABLE containers DROP COLUMN enable_auto_bind\n")
1652 _T("<END>");
feab3324
VK
1653 CHK_EXEC(SQLBatch(batch));
1654
1655 CHK_EXEC(CreateEventTemplate(EVENT_CONTAINER_AUTOBIND, _T("SYS_CONTAINER_AUTOBIND"), EVENT_SEVERITY_NORMAL, 1,
6f33021d 1656 _T("Node %2 automatically bound to container %4"),
feab3324
VK
1657 _T("Generated when node bound to container object by autobind rule.\r\n")
1658 _T("Parameters:#\r\n")
1659 _T(" 1) Node ID\r\n")
1660 _T(" 2) Node name\r\n")
1661 _T(" 3) Container ID\r\n")
1662 _T(" 4) Container name")
1663 ));
1664
1665 CHK_EXEC(CreateEventTemplate(EVENT_CONTAINER_AUTOUNBIND, _T("SYS_CONTAINER_AUTOUNBIND"), EVENT_SEVERITY_NORMAL, 1,
6f33021d 1666 _T("Node %2 automatically unbound from container %4"),
feab3324
VK
1667 _T("Generated when node unbound from container object by autobind rule.\r\n")
1668 _T("Parameters:#\r\n")
1669 _T(" 1) Node ID\r\n")
1670 _T(" 2) Node name\r\n")
1671 _T(" 3) Container ID\r\n")
1672 _T(" 4) Container name")
1673 ));
1674
1675 CHK_EXEC(CreateEventTemplate(EVENT_TEMPLATE_AUTOAPPLY, _T("SYS_TEMPLATE_AUTOAPPLY"), EVENT_SEVERITY_NORMAL, 1,
6f33021d 1676 _T("Template %4 automatically applied to node %2"),
feab3324
VK
1677 _T("Generated when template applied to node by autoapply rule.\r\n")
1678 _T("Parameters:#\r\n")
1679 _T(" 1) Node ID\r\n")
1680 _T(" 2) Node name\r\n")
1681 _T(" 3) Template ID\r\n")
1682 _T(" 4) Template name")
1683 ));
1684
1685 CHK_EXEC(CreateEventTemplate(EVENT_TEMPLATE_AUTOREMOVE, _T("SYS_TEMPLATE_AUTOREMOVE"), EVENT_SEVERITY_NORMAL, 1,
6f33021d 1686 _T("Template %4 automatically removed from node %2"),
feab3324
VK
1687 _T("Generated when template removed from node by autoapply rule.\r\n")
1688 _T("Parameters:#\r\n")
1689 _T(" 1) Node ID\r\n")
1690 _T(" 2) Node name\r\n")
1691 _T(" 3) Template ID\r\n")
1692 _T(" 4) Template name")
1693 ));
1694
65790062
VK
1695 TCHAR buffer[64];
1696 _sntprintf(buffer, 64, _T("%d"), ConfigReadInt(_T("AllowedCiphers"), 15) + 16);
1697 CreateConfigParam(_T("AllowedCiphers"), buffer, 1, 1, TRUE);
1698
feab3324
VK
1699 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='253' WHERE var_name='SchemaVersion'")));
1700 return TRUE;
1701}
1702
badf9a95
VK
1703/**
1704 * Upgrade from V251 to V252
1705 */
1e6b68a6
VK
1706static BOOL H_UpgradeFromV251(int currVersion, int newVersion)
1707{
6f33021d 1708 static TCHAR batch[] =
1e6b68a6
VK
1709 _T("ALTER TABLE interfaces ADD admin_state integer\n")
1710 _T("ALTER TABLE interfaces ADD oper_state integer\n")
1711 _T("UPDATE interfaces SET admin_state=0,oper_state=0\n")
1712 _T("<END>");
1713
1714 CHK_EXEC(SQLBatch(batch));
1715
1716 CHK_EXEC(CreateEventTemplate(EVENT_INTERFACE_UNEXPECTED_UP, _T("SYS_IF_UNEXPECTED_UP"), EVENT_SEVERITY_MAJOR, 1,
6f33021d 1717 _T("Interface \"%2\" unexpectedly changed state to UP (IP Addr: %3/%4, IfIndex: %5)"),
1e6b68a6
VK
1718 _T("Generated when interface goes up but it's expected state set to DOWN.\r\n")
1719 _T("Please note that source of event is node, not an interface itself.\r\n")
1720 _T("Parameters:#\r\n")
1721 _T(" 1) Interface object ID\r\n")
1722 _T(" 2) Interface name\r\n")
1723 _T(" 3) Interface IP address\r\n")
1724 _T(" 4) Interface netmask\r\n")
1725 _T(" 5) Interface index")
1726 ));
1727
1728 CHK_EXEC(CreateEventTemplate(EVENT_INTERFACE_EXPECTED_DOWN, _T("SYS_IF_EXPECTED_DOWN"), EVENT_SEVERITY_NORMAL, 1,
6f33021d 1729 _T("Interface \"%2\" with expected state DOWN changed state to DOWN (IP Addr: %3/%4, IfIndex: %5)"),
1e6b68a6
VK
1730 _T("Generated when interface goes down and it's expected state is DOWN.\r\n")
1731 _T("Please note that source of event is node, not an interface itself.\r\n")
1732 _T("Parameters:#\r\n")
1733 _T(" 1) Interface object ID\r\n")
1734 _T(" 2) Interface name\r\n")
1735 _T(" 3) Interface IP address\r\n")
1736 _T(" 4) Interface netmask\r\n")
1737 _T(" 5) Interface index")
1738 ));
1739
1740 // Create rule pair in event processing policy
1741 int ruleId = 0;
1742 DB_RESULT hResult = SQLSelect(_T("SELECT max(rule_id) FROM event_policy"));
1743 if (hResult != NULL)
1744 {
1745 ruleId = DBGetFieldLong(hResult, 0, 0) + 1;
1746 DBFreeResult(hResult);
1747 }
1748
1749 TCHAR query[1024];
6f33021d 1750 _sntprintf(query, 1024,
1e6b68a6
VK
1751 _T("INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,")
1752 _T("script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES ")
1753 _T("(%d,7944,'Show alarm when interface is unexpectedly up','%%m',5,'IF_UNEXP_UP_%%i_%%1',")
1754 _T("'#00',0,%d,0,'#00')"), ruleId, EVENT_ALARM_TIMEOUT);
1755 CHK_EXEC(SQLQuery(query));
1756 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_INTERFACE_UNEXPECTED_UP);
1757 CHK_EXEC(SQLQuery(query));
1758 ruleId++;
1759
6f33021d 1760 _sntprintf(query, 1024,
1e6b68a6
VK
1761 _T("INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,")
1762 _T("script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES ")
1763 _T("(%d,7944,'Acknowlege interface unexpectedly up alarms when interface goes down','%%m',")
1764 _T("6,'IF_UNEXP_UP_%%i_%%1','#00',0,%d,0,'#00')"), ruleId, EVENT_ALARM_TIMEOUT);
1765 CHK_EXEC(SQLQuery(query));
1766 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_INTERFACE_EXPECTED_DOWN);
1767 CHK_EXEC(SQLQuery(query));
1768
1769 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='252' WHERE var_name='SchemaVersion'")));
1770 return TRUE;
1771}
1772
9aa67910
VK
1773/**
1774 * Upgrade from V250 to V251
1775 */
711e5e9a
VK
1776static BOOL H_UpgradeFromV250(int currVersion, int newVersion)
1777{
6f33021d 1778 static TCHAR batch[] =
711e5e9a
VK
1779 _T("ALTER TABLE thresholds ADD current_severity integer\n")
1780 _T("ALTER TABLE thresholds ADD last_event_timestamp integer\n")
1781 _T("UPDATE thresholds SET current_severity=0,last_event_timestamp=0\n")
1782 _T("<END>");
1783
1784 CHK_EXEC(SQLBatch(batch));
1785
480e036b
VK
1786 CHK_EXEC(SetColumnNullable(_T("thresholds"), _T("fire_value")));
1787 CHK_EXEC(SetColumnNullable(_T("thresholds"), _T("rearm_value")));
711e5e9a
VK
1788 CHK_EXEC(ConvertStrings(_T("thresholds"), _T("threshold_id"), _T("fire_value")));
1789 CHK_EXEC(ConvertStrings(_T("thresholds"), _T("threshold_id"), _T("rearm_value")));
1790
1791 CHK_EXEC(CreateConfigParam(_T("EnableNXSLContainerFunctions"), _T("1"), 1, 1));
1792 CHK_EXEC(CreateConfigParam(_T("UseDNSNameForDiscoveredNodes"), _T("0"), 1, 0));
1793 CHK_EXEC(CreateConfigParam(_T("AllowTrapVarbindsConversion"), _T("1"), 1, 1));
1794
1795 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='251' WHERE var_name='SchemaVersion'")));
1796 return TRUE;
1797}
1798
9aa67910
VK
1799/**
1800 * Upgrade from V249 to V250
1801 */
ae2a3458
VK
1802static BOOL H_UpgradeFromV249(int currVersion, int newVersion)
1803{
1804 CHK_EXEC(CreateTable(_T("CREATE TABLE licenses (")
1805 _T("id integer not null,")
1806 _T("content $SQL:TEXT null,")
1807 _T("PRIMARY KEY(id))")));
1808
1809 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='250' WHERE var_name='SchemaVersion'")));
1810 return TRUE;
1811}
1812
9aa67910
VK
1813/**
1814 * Upgrade from V248 to V249
1815 */
d6124fa0
VK
1816#define TDATA_CREATE_QUERY _T("CREATE TABLE tdata_%d (item_id integer not null,tdata_timestamp integer not null,tdata_row integer not null,tdata_column integer not null,tdata_value varchar(255) null)")
1817#define TDATA_INDEX_MSSQL _T("CREATE CLUSTERED INDEX idx_tdata_%d_id_timestamp ON tdata_%d(item_id,tdata_timestamp)")
1818#define TDATA_INDEX_PGSQL _T("CREATE INDEX idx_tdata_%d_timestamp_id ON tdata_%d(tdata_timestamp,item_id)")
1819#define TDATA_INDEX_DEFAULT _T("CREATE INDEX idx_tdata_%d_id_timestamp ON tdata_%d(item_id,tdata_timestamp)")
1820
1821static BOOL CreateTData(DWORD nodeId)
1822{
1823 TCHAR query[256];
1824
1825 _sntprintf(query, 256, TDATA_CREATE_QUERY, (int)nodeId);
1826 CHK_EXEC(SQLQuery(query));
1827
1828 switch(g_iSyntax)
1829 {
1830 case DB_SYNTAX_MSSQL:
1831 _sntprintf(query, 256, TDATA_INDEX_MSSQL, (int)nodeId, (int)nodeId);
1832 break;
1833 case DB_SYNTAX_PGSQL:
1834 _sntprintf(query, 256, TDATA_INDEX_PGSQL, (int)nodeId, (int)nodeId);
1835 break;
1836 default:
1837 _sntprintf(query, 256, TDATA_INDEX_DEFAULT, (int)nodeId, (int)nodeId);
1838 break;
1839 }
1840 CHK_EXEC(SQLQuery(query));
1841
1842 return TRUE;
1843}
1844
1845static BOOL H_UpgradeFromV248(int currVersion, int newVersion)
1846{
1847 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataTableCreationCommand','") TDATA_CREATE_QUERY _T("')")));
1848
1849 switch(g_iSyntax)
1850 {
1851 case DB_SYNTAX_MSSQL:
1852 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataIndexCreationCommand_0','") TDATA_INDEX_MSSQL _T("')")));
1853 break;
1854 case DB_SYNTAX_PGSQL:
1855 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataIndexCreationCommand_0','") TDATA_INDEX_PGSQL _T("')")));
1856 break;
1857 default:
1858 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataIndexCreationCommand_0','") TDATA_INDEX_DEFAULT _T("')")));
1859 break;
1860 }
1861
1862 CHK_EXEC(CreateTable(_T("CREATE TABLE dct_column_names (")
1863 _T("column_id integer not null,")
1864 _T("column_name varchar(63) not null,")
1865 _T("PRIMARY KEY(column_id))")));
1866
1867 DB_RESULT hResult = SQLSelect(_T("SELECT id FROM nodes"));
1868 if (hResult != NULL)
1869 {
1870 int count = DBGetNumRows(hResult);
1871 for(int i = 0 ; i < count; i++)
1872 {
1873 if (!CreateTData(DBGetFieldULong(hResult, i, 0)))
1874 {
1875 if (!g_bIgnoreErrors)
1876 {
1877 DBFreeResult(hResult);
1878 return FALSE;
1879 }
1880 }
1881 }
1882 DBFreeResult(hResult);
1883 }
1884 else
1885 {
1886 if (!g_bIgnoreErrors)
1887 return FALSE;
1888 }
1889
1890 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='249' WHERE var_name='SchemaVersion'")));
1891 return TRUE;
1892}
1893
480e036b
VK
1894/**
1895 * Upgrade from V247 to V248
1896 */
cc8ce218
VK
1897static BOOL H_UpgradeFromV247(int currVersion, int newVersion)
1898{
1899 CHK_EXEC(CreateTable(_T("CREATE TABLE dc_tables (")
1900 _T("item_id integer not null,")
1901 _T("node_id integer not null,")
1902 _T("template_id integer not null,")
1903 _T("template_item_id integer not null,")
1904 _T("name varchar(255) null,")
1905 _T("instance_column varchar(63) null,")
1906 _T("description varchar(255) null,")
1907 _T("flags integer not null,")
1908 _T("source integer not null,")
1909 _T("snmp_port integer not null,")
1910 _T("polling_interval integer not null,")
1911 _T("retention_time integer not null,")
1912 _T("status integer not null,")
1913 _T("system_tag varchar(255) null,")
1914 _T("resource_id integer not null,")
1915 _T("proxy_node integer not null,")
1916 _T("perftab_settings $SQL:TEXT null,")
1917 _T("PRIMARY KEY(item_id))")));
1918
1919 CHK_EXEC(CreateTable(_T("CREATE TABLE dc_table_columns (")
1920 _T("table_id integer not null,")
1921 _T("column_name varchar(63) not null,")
1922 _T("snmp_oid varchar(1023) null,")
1923 _T("data_type integer not null,")
1924 _T("transformation_script $SQL:TEXT null,")
1925 _T("PRIMARY KEY(table_id,column_name))")));
1926
1927 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='248' WHERE var_name='SchemaVersion'")));
1928 return TRUE;
1929}
1930
480e036b
VK
1931/**
1932 * Upgrade from V246 to V247
1933 */
ff392ecf
VK
1934static BOOL H_UpgradeFromV246(int currVersion, int newVersion)
1935{
1936 static TCHAR insertQuery[] = _T("INSERT INTO object_custom_attributes (object_id,attr_name,attr_value) VALUES (?,?,?)");
1937
480e036b 1938 CHK_EXEC(SetColumnNullable(_T("object_custom_attributes"), _T("attr_value")));
ff392ecf
VK
1939
1940 // Convert strings in object_custom_attributes table
1941 DB_RESULT hResult = SQLSelect(_T("SELECT object_id,attr_name,attr_value FROM object_custom_attributes"));
1942 if (hResult != NULL)
1943 {
1944 if (SQLQuery(_T("DELETE FROM object_custom_attributes")))
1945 {
1946 TCHAR errorText[DBDRV_MAX_ERROR_TEXT];
1947 DB_STATEMENT hStmt = DBPrepareEx(g_hCoreDB, insertQuery, errorText);
1948 if (hStmt != NULL)
1949 {
1950 TCHAR name[128], *value;
1951 int count = DBGetNumRows(hResult);
1952 for(int i = 0; i < count; i++)
1953 {
967893bb 1954 UINT32 id = DBGetFieldULong(hResult, i, 0);
ff392ecf
VK
1955 DBGetField(hResult, i, 1, name, 128);
1956 DecodeSQLString(name);
1957 value = DBGetField(hResult, i, 2, NULL, 0);
1958 DecodeSQLString(value);
1959
1960 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, id);
1961 DBBind(hStmt, 2, DB_SQLTYPE_VARCHAR, name, DB_BIND_STATIC);
1962 DBBind(hStmt, 3, DB_SQLTYPE_VARCHAR, value, DB_BIND_DYNAMIC);
1963 if (g_bTrace)
1964 ShowQuery(insertQuery);
1965 if (!DBExecuteEx(hStmt, errorText))
1966 {
1967 WriteToTerminalEx(_T("SQL query failed (%s):\n\x1b[33;1m%s\x1b[0m\n"), errorText, insertQuery);
1968 if (!g_bIgnoreErrors)
1969 {
1970 DBFreeStatement(hStmt);
1971 DBFreeResult(hResult);
1972 return FALSE;
1973 }
1974 }
1975 }
1976 DBFreeStatement(hStmt);
1977 }
1978 else
1979 {
1980 WriteToTerminalEx(_T("SQL query failed (%s):\n\x1b[33;1m%s\x1b[0m\n"), errorText, insertQuery);
1981 if (!g_bIgnoreErrors)
1982 {
1983 DBFreeResult(hResult);
1984 return FALSE;
1985 }
1986 }
1987 }
1988 else
1989 {
1990 if (!g_bIgnoreErrors)
1991 {
1992 DBFreeResult(hResult);
1993 return FALSE;
1994 }
1995 }
1996
1997 DBFreeResult(hResult);
1998 }
1999 else
2000 {
2001 if (!g_bIgnoreErrors)
2002 return FALSE;
2003 }
2004
2005 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_ocattr_oid ON object_custom_attributes(object_id)")));
2006 CHK_EXEC(CreateConfigParam(_T("AlarmHistoryRetentionTime"), _T("180"), 1, 0));
2007
2008 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='247' WHERE var_name='SchemaVersion'")));
2009 return TRUE;
2010}
2011
d6bf58f9
VK
2012/**
2013 * Upgrade from V245 to V246
2014 */
98cd01bb
VK
2015static BOOL H_UpgradeFromV245(int currVersion, int newVersion)
2016{
6f33021d 2017 static TCHAR batch[] =
98cd01bb
VK
2018 _T("ALTER TABLE snmp_trap_pmap ADD flags integer\n")
2019 _T("UPDATE snmp_trap_pmap SET flags=0\n")
2020 _T("<END>");
2021
2022 CHK_EXEC(SQLBatch(batch));
2023
480e036b 2024 CHK_EXEC(SetColumnNullable(_T("snmp_trap_pmap"), _T("description")));
d6bf58f9 2025 CHK_EXEC(ConvertStrings(_T("snmp_trap_pmap"), _T("trap_id"), _T("parameter"), _T("description"), false));
6f33021d 2026
480e036b 2027 CHK_EXEC(SetColumnNullable(_T("cluster_resources"), _T("resource_name")));
d6bf58f9 2028 CHK_EXEC(ConvertStrings(_T("cluster_resources"), _T("cluster_id"), _T("resource_id"), _T("resource_name"), false));
6f33021d 2029
98cd01bb
VK
2030 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='246' WHERE var_name='SchemaVersion'")));
2031 return TRUE;
2032}
2033
d6bf58f9
VK
2034/**
2035 * Upgrade from V244 to V245
2036 */
4866d57b
VK
2037static BOOL H_UpgradeFromV244(int currVersion, int newVersion)
2038{
6f33021d 2039 static TCHAR batch[] =
4866d57b
VK
2040 _T("ALTER TABLE nodes ADD runtime_flags integer\n")
2041 _T("UPDATE nodes SET runtime_flags=0\n")
2042 _T("<END>");
2043
2044 CHK_EXEC(SQLBatch(batch));
2045
480e036b
VK
2046 CHK_EXEC(SetColumnNullable(_T("actions"), _T("rcpt_addr")));
2047 CHK_EXEC(SetColumnNullable(_T("actions"), _T("email_subject")));
2048 CHK_EXEC(SetColumnNullable(_T("actions"), _T("action_data")));
4866d57b
VK
2049
2050 CHK_EXEC(ConvertStrings(_T("actions"), _T("action_id"), _T("rcpt_addr")));
2051 CHK_EXEC(ConvertStrings(_T("actions"), _T("action_id"), _T("email_subject")));
2052 CHK_EXEC(ConvertStrings(_T("actions"), _T("action_id"), _T("action_data")));
6f33021d 2053
4866d57b
VK
2054 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='245' WHERE var_name='SchemaVersion'")));
2055 return TRUE;
2056}
2057
2058
aa16f82b
VK
2059//
2060// Upgrade from V243 to V244
2061//
2062
2063static BOOL H_UpgradeFromV243(int currVersion, int newVersion)
2064{
6f33021d 2065 static TCHAR batch[] =
aa16f82b
VK
2066 _T("ALTER TABLE interfaces ADD dot1x_pae_state integer\n")
2067 _T("ALTER TABLE interfaces ADD dot1x_backend_state integer\n")
2068 _T("UPDATE interfaces SET dot1x_pae_state=0,dot1x_backend_state=0\n")
2069 _T("<END>");
2070
2071 CHK_EXEC(SQLBatch(batch));
2072
2073 CHK_EXEC(CreateEventTemplate(EVENT_8021X_PAE_STATE_CHANGED, _T("SYS_8021X_PAE_STATE_CHANGED"),
6f33021d 2074 EVENT_SEVERITY_NORMAL, 1, _T("Port %6 PAE state changed from %4 to %2"),
aa16f82b
VK
2075 _T("Generated when switch port PAE state changed.\r\nParameters:\r\n")
2076 _T(" 1) New PAE state code\r\n")
2077 _T(" 2) New PAE state as text\r\n")
2078 _T(" 3) Old PAE state code\r\n")
2079 _T(" 4) Old PAE state as text\r\n")
2080 _T(" 5) Interface index\r\n")
2081 _T(" 6) Interface name")));
2082
2083 CHK_EXEC(CreateEventTemplate(EVENT_8021X_BACKEND_STATE_CHANGED, _T("SYS_8021X_BACKEND_STATE_CHANGED"),
6f33021d 2084 EVENT_SEVERITY_NORMAL, 1, _T("Port %6 backend authentication state changed from %4 to %2"),
aa16f82b
VK
2085 _T("Generated when switch port backend authentication state changed.\r\nParameters:\r\n")
2086 _T(" 1) New backend state code\r\n")
2087 _T(" 2) New backend state as text\r\n")
2088 _T(" 3) Old backend state code\r\n")
2089 _T(" 4) Old backend state as text\r\n")
2090 _T(" 5) Interface index\r\n")
2091 _T(" 6) Interface name")));
2092
2093 CHK_EXEC(CreateEventTemplate(EVENT_8021X_PAE_FORCE_UNAUTH, _T("SYS_8021X_PAE_FORCE_UNAUTH"),
6f33021d 2094 EVENT_SEVERITY_MAJOR, 1, _T("Port %2 switched to force unauthorize state"),
aa16f82b
VK
2095 _T("Generated when switch port PAE state changed to FORCE UNAUTHORIZE.\r\nParameters:\r\n")
2096 _T(" 1) Interface index\r\n")
2097 _T(" 2) Interface name")));
2098
2099 CHK_EXEC(CreateEventTemplate(EVENT_8021X_AUTH_FAILED, _T("SYS_8021X_AUTH_FAILED"),
6f33021d 2100 EVENT_SEVERITY_MAJOR, 1, _T("802.1x authentication failed on port %2"),
aa16f82b
VK
2101 _T("Generated when switch port backend authentication state changed to FAIL.\r\nParameters:\r\n")
2102 _T(" 1) Interface index\r\n")
2103 _T(" 2) Interface name")));
2104
2105 CHK_EXEC(CreateEventTemplate(EVENT_8021X_AUTH_TIMEOUT, _T("SYS_8021X_AUTH_TIMEOUT"),
6f33021d 2106 EVENT_SEVERITY_MAJOR, 1, _T("802.1x authentication time out on port %2"),
aa16f82b
VK
2107 _T("Generated when switch port backend authentication state changed to TIMEOUT.\r\nParameters:\r\n")
2108 _T(" 1) Interface index\r\n")
2109 _T(" 2) Interface name")));
2110
2111 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='244' WHERE var_name='SchemaVersion'")));
2112 return TRUE;
2113}
2114
2115
e320f8ce
VK
2116//
2117// Upgrade from V242 to V243
2118//
2119
2120static BOOL H_UpgradeFromV242(int currVersion, int newVersion)
2121{
6f33021d 2122 static TCHAR batch[] =
242e9c7f
VK
2123 _T("ALTER TABLE items ADD snmp_raw_value_type integer\n")
2124 _T("UPDATE items SET snmp_raw_value_type=0\n")
e320f8ce
VK
2125 _T("ALTER TABLE items ADD flags integer\n")
2126 _T("UPDATE items SET flags=adv_schedule+(all_thresholds*2)\n")
2127 _T("ALTER TABLE items DROP COLUMN adv_schedule\n")
2128 _T("ALTER TABLE items DROP COLUMN all_thresholds\n")
e320f8ce
VK
2129 _T("<END>");
2130
2131 CHK_EXEC(SQLBatch(batch));
2132 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='243' WHERE var_name='SchemaVersion'")));
2133 return TRUE;
2134}
2135
2136
f5e80875
VK
2137//
2138// Upgrade from V241 to V242
2139//
2140
2141static BOOL H_UpgradeFromV241(int currVersion, int newVersion)
2142{
6f33021d 2143 static TCHAR batch[] =
f5e80875
VK
2144 _T("DROP TABLE business_service_templates\n")
2145 _T("ALTER TABLE dashboards ADD options integer\n")
2146 _T("UPDATE dashboards SET options=0\n")
2147 _T("<END>");
2148
2149 CHK_EXEC(SQLBatch(batch));
2150 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='242' WHERE var_name='SchemaVersion'")));
2151 return TRUE;
2152}
2153
2154
6ff21d27
VK
2155//
2156// Upgrade from V240 to V241
2157//
2158
2159static BOOL H_UpgradeFromV240(int currVersion, int newVersion)
2160{
6f33021d 2161 static TCHAR batch[] =
6ff21d27
VK
2162 _T("ALTER TABLE slm_checks ADD template_id integer\n")
2163 _T("ALTER TABLE slm_checks ADD current_ticket integer\n")
2164 _T("UPDATE slm_checks SET template_id=0,current_ticket=0\n")
2165 _T("<END>");
2166
2167 CHK_EXEC(SQLBatch(batch));
2168 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='241' WHERE var_name='SchemaVersion'")));
2169 return TRUE;
2170}
2171
2172
5fe19f9e
VK
2173//
2174// Upgrade from V239 to V240
2175//
2176
2177static BOOL H_UpgradeFromV239(int currVersion, int newVersion)
2178{
2179 CHK_EXEC(SQLQuery(_T("ALTER TABLE raw_dci_values ADD transformed_value varchar(255)")));
2180 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='240' WHERE var_name='SchemaVersion'")));
2181 return TRUE;
2182}
2183
2184
5a7d6a10
VK
2185//
2186// Upgrade from V238 to V239
2187//
2188
2189static BOOL H_UpgradeFromV238(int currVersion, int newVersion)
2190{
2191 CHK_EXEC(SQLQuery(
2192 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES ")
2193 _T("(56,'SYS_IP_ADDRESS_CHANGED',1,1,'Primary IP address changed from %2 to %1',")
2194 _T("'Generated when primary IP address changed (usually because of primary name change or DNS change).#0D#0A")
2195 _T("Parameters:#0D#0A 1) New IP address#0D#0A 2) Old IP address#0D#0A 3) Primary host name')")));
2196
2197 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='239' WHERE var_name='SchemaVersion'")));
2198 return TRUE;
2199}
2200
2201
34ccf87f
VK
2202//
2203// Upgrade from V232 to V238
2204//
2205
2206static BOOL H_UpgradeFromV232toV238(int currVersion, int newVersion)
2207{
2208 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_checks (")
2209 _T("id integer not null,")
2210 _T("type integer not null,")
2211 _T("content $SQL:TEXT null,")
2212 _T("threshold_id integer not null,")
2213 _T("reason varchar(255) null,")
2214 _T("is_template integer not null,")
2215 _T("PRIMARY KEY(id))")));
2216
2217 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_tickets (")
2218 _T("ticket_id integer not null,")
2219 _T("service_id integer not null,")
2220 _T("check_id integer not null,")
2221 _T("create_timestamp integer not null,")
2222 _T("close_timestamp integer not null,")
2223 _T("reason varchar(255) null,")
2224 _T("PRIMARY KEY(ticket_id))")));
2225
2226 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_service_history (")
2227 _T("record_id integer not null,")
2228 _T("service_id integer not null,")
2229 _T("change_timestamp integer not null,")
2230 _T("new_status integer not null,")
2231 _T("PRIMARY KEY(record_id))")));
2232
2233 CHK_EXEC(CreateTable(_T("CREATE TABLE report_results (")
2234 _T("report_id integer not null,")
2235 _T("generated integer not null,")
2236 _T("job_id integer not null,")
2237 _T("PRIMARY KEY(report_id,job_id))")));
2238
2239 CHK_EXEC(CreateTable(_T("CREATE TABLE reports (")
2240 _T("id integer not null,")
2241 _T("definition $SQL:TEXT null,")
2242 _T("PRIMARY KEY(id))")));
2243
2244 CHK_EXEC(CreateTable(_T("CREATE TABLE job_history (")
2245 _T("id integer not null,")
2246 _T("time_created integer not null,")
2247 _T("time_started integer not null,")
2248 _T("time_finished integer not null,")
2249 _T("job_type varchar(127) null,")
2250 _T("description varchar(255) null,")
2251 _T("additional_info varchar(255) null,")
2252 _T("node_id integer not null,")
2253 _T("user_id integer not null,")
2254 _T("status integer not null,")
2255 _T("failure_message varchar(255) null,")
2256 _T("PRIMARY KEY(id))")));
2257
2258 CHK_EXEC(CreateTable(_T("CREATE TABLE business_services (")
2259 _T("service_id integer not null,")
2260 _T("PRIMARY KEY(service_id))")));
2261
2262 CHK_EXEC(CreateTable(_T("CREATE TABLE business_service_templates (")
2263 _T("service_id integer not null,")
2264 _T("template_id integer not null,")
2265 _T("PRIMARY KEY(service_id,template_id))")));
2266
2267 CHK_EXEC(CreateTable(_T("CREATE TABLE node_links (")
2268 _T("nodelink_id integer not null,")
2269 _T("node_id integer not null,")
2270 _T("PRIMARY KEY(nodelink_id))")));
2271
2272 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_agreements (")
2273 _T("agreement_id integer not null,")
2274 _T("service_id integer not null,")
2275 _T("org_id integer not null,")
2276 _T("uptime varchar(63) not null,")
2277 _T("period integer not null,")
2278 _T("start_date integer not null,")
2279 _T("notes varchar(255),")
2280 _T("PRIMARY KEY(agreement_id))")));
2281
2282 CHK_EXEC(CreateTable(_T("CREATE TABLE organizations (")
2283 _T("id integer not null,")
2284 _T("parent_id integer not null,")
2285 _T("org_type integer not null,")
2286 _T("name varchar(63) not null,")
2287 _T("description varchar(255),")
2288 _T("manager integer not null,")
2289 _T("PRIMARY KEY(id))")));
2290
2291 CHK_EXEC(CreateTable(_T("CREATE TABLE persons (")
2292 _T("id integer not null,")
2293 _T("org_id integer not null,")
2294 _T("first_name varchar(63),")
2295 _T("last_name varchar(63),")
2296 _T("title varchar(255),")
2297 _T("status integer not null,")
2298 _T("PRIMARY KEY(id))")));
2299
2300 CHK_EXEC(CreateConfigParam(_T("JobHistoryRetentionTime"), _T("90"), 1, 0));
2301
2302 CHK_EXEC(SQLQuery(_T("UPDATE event_cfg SET description=")
2303 _T("'Generated when threshold check is rearmed for specific data collection item.#0D#0A")
2304 _T("Parameters:#0D#0A")
2305 _T(" 1) Parameter name#0D#0A")
2306 _T(" 2) Item description#0D#0A")
2307 _T(" 3) Data collection item ID#0D#0A")
2308 _T(" 4) Instance#0D#0A")
2309 _T(" 5) Threshold value#0D#0A")
2310 _T(" 6) Actual value' WHERE event_code=18")));
2311
2312 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='238' WHERE var_name='SchemaVersion'")));
2313 return TRUE;
2314}
2315
2316
9c529287
VK
2317//
2318// Upgrade from V237 to V238
2319//
2320
2321static BOOL H_UpgradeFromV237(int currVersion, int newVersion)
2322{
6f33021d 2323 static TCHAR batch[] =
9c529287
VK
2324 _T("DROP TABLE slm_check_templates\n")
2325 _T("DROP TABLE node_link_checks\n")
2326 _T("DROP TABLE slm_checks\n")
2327 _T("DROP TABLE slm_tickets\n")
2328 _T("<END>");
2329
2330 CHK_EXEC(SQLBatch(batch));
2331
2332 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_checks (")
2333 _T("id integer not null,")
2334 _T("type integer not null,")
2335 _T("content $SQL:TEXT null,")
2336 _T("threshold_id integer not null,")
2337 _T("reason varchar(255) null,")
2338 _T("is_template integer not null,")
2339 _T("PRIMARY KEY(id))")));
2340
2341 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_tickets (")
2342 _T("ticket_id integer not null,")
2343 _T("service_id integer not null,")
2344 _T("check_id integer not null,")
2345 _T("create_timestamp integer not null,")
2346 _T("close_timestamp integer not null,")
2347 _T("reason varchar(255) null,")
2348 _T("PRIMARY KEY(ticket_id))")));
2349
2350 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_service_history (")
2351 _T("record_id integer not null,")
2352 _T("service_id integer not null,")
2353 _T("change_timestamp integer not null,")
2354 _T("new_status integer not null,")
2355 _T("PRIMARY KEY(record_id))")));
2356
2357 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='238' WHERE var_name='SchemaVersion'")));
2358 return TRUE;
2359}
2360
2361
f5c9fdc5
VK
2362//
2363// Upgrade from V236 to V237
2364//
2365
2366static BOOL H_UpgradeFromV236(int currVersion, int newVersion)
2367{
6f33021d 2368 static TCHAR batch[] =
f5c9fdc5
VK
2369 _T("ALTER TABLE business_services DROP COLUMN name\n")
2370 _T("ALTER TABLE business_services DROP COLUMN parent_id\n")
2371 _T("ALTER TABLE business_services DROP COLUMN status\n")
2372 _T("ALTER TABLE slm_checks DROP COLUMN name\n")
2373 _T("<END>");
2374
2375 CHK_EXEC(SQLBatch(batch));
2376
2377 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='237' WHERE var_name='SchemaVersion'")));
2378 return TRUE;
2379}
2380
2381
5418326b
AK
2382//
2383// Upgrade from V235 to V236
2384//
2385
2386static BOOL H_UpgradeFromV235(int currVersion, int newVersion)
2387{
2388 CHK_EXEC(CreateTable(_T("CREATE TABLE report_results (")
2389 _T("report_id integer not null,")
2390 _T("generated integer not null,")
2391 _T("job_id integer not null,")
2392 _T("PRIMARY KEY(report_id,job_id))")));
2393
2394 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='236' WHERE var_name='SchemaVersion'")));
2395 return TRUE;
2396}
2397
2398
845b8121
VK
2399//
2400// Upgrade from V234 to V235
2401//
2402
2403static BOOL H_UpgradeFromV234(int currVersion, int newVersion)
2404{
2405 CHK_EXEC(CreateTable(_T("CREATE TABLE reports (")
2406 _T("id integer not null,")
2407 _T("definition $SQL:TEXT null,")
2408 _T("PRIMARY KEY(id))")));
2409
845b8121
VK
2410 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='235' WHERE var_name='SchemaVersion'")));
2411 return TRUE;
2412}
2413
2414
878b4261
VK
2415//
2416// Upgrade from V233 to V234
2417//
2418
2419static BOOL H_UpgradeFromV233(int currVersion, int newVersion)
2420{
2421 CHK_EXEC(CreateTable(_T("CREATE TABLE job_history (")
2422 _T("id integer not null,")
2423 _T("time_created integer not null,")
2424 _T("time_started integer not null,")
2425 _T("time_finished integer not null,")
2426 _T("job_type varchar(127) null,")
2427 _T("description varchar(255) null,")
24dc5346 2428 _T("additional_info varchar(255) null,")
878b4261
VK
2429 _T("node_id integer not null,")
2430 _T("user_id integer not null,")
2431 _T("status integer not null,")
2432 _T("failure_message varchar(255) null,")
2433 _T("PRIMARY KEY(id))")));
2434
2435 CHK_EXEC(CreateConfigParam(_T("JobHistoryRetentionTime"), _T("90"), 1, 0));
2436
2437 CHK_EXEC(SQLQuery(_T("UPDATE event_cfg SET description=")
2438 _T("'Generated when threshold check is rearmed for specific data collection item.#0D#0A")
2439 _T("Parameters:#0D#0A")
2440 _T(" 1) Parameter name#0D#0A")
2441 _T(" 2) Item description#0D#0A")
2442 _T(" 3) Data collection item ID#0D#0A")
2443 _T(" 4) Instance#0D#0A")
2444 _T(" 5) Threshold value#0D#0A")
2445 _T(" 6) Actual value' WHERE event_code=18")));
2446
2447 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='234' WHERE var_name='SchemaVersion'")));
2448 return TRUE;
2449}
2450
2451
128681c8
VK
2452//
2453// Upgrade from V232 to V233
2454//
2455
2456static BOOL H_UpgradeFromV232(int currVersion, int newVersion)
2457{
2458 CHK_EXEC(CreateTable(_T("CREATE TABLE business_services (")
2459 _T("service_id integer not null,")
2460 _T("name varchar(63) not null,")
2498594e
VK
2461 _T("parent_id integer not null,")
2462 _T("status integer not null,")
128681c8
VK
2463 _T("PRIMARY KEY(service_id))")));
2464
128681c8
VK
2465 CHK_EXEC(CreateTable(_T("CREATE TABLE business_service_templates (")
2466 _T("service_id integer not null,")
2467 _T("template_id integer not null,")
2468 _T("PRIMARY KEY(service_id,template_id))")));
2469
2470 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_checks (")
2471 _T("check_id integer not null,")
2472 _T("name varchar(63) not null,")
2498594e 2473 _T("type integer not null,")
128681c8 2474 _T("content $SQL:TEXT,")
2498594e 2475 _T("threshold_id integer not null,")
128681c8
VK
2476 _T("state integer not null,")
2477 _T("reason varchar(255) not null,")
2478 _T("PRIMARY KEY(check_id))")));
2479
2480 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_check_templates (")
2481 _T("id integer not null,")
2482 _T("name varchar(63) not null,")
2498594e 2483 _T("type integer not null,")
128681c8 2484 _T("content $SQL:TEXT,")
2498594e 2485 _T("threshold_id integer not null,")
128681c8
VK
2486 _T("PRIMARY KEY(id))")));
2487
2488 CHK_EXEC(CreateTable(_T("CREATE TABLE node_links (")
2489 _T("nodelink_id integer not null,")
2490 _T("node_id integer not null,")
2491 _T("PRIMARY KEY(nodelink_id))")));
2492
2493 CHK_EXEC(CreateTable(_T("CREATE TABLE node_link_checks (")
2494 _T("nodelink_id integer not null,")
2495 _T("check_id integer not null,")
2496 _T("PRIMARY KEY(nodelink_id,check_id))")));
2497
2498 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_agreements (")
2499 _T("agreement_id integer not null,")
2500 _T("service_id integer not null,")
2501 _T("org_id integer not null,")
2502 _T("uptime varchar(63) not null,")
2503 _T("period integer not null,")
2504 _T("start_date integer not null,")
2505 _T("notes varchar(255),")
2506 _T("PRIMARY KEY(agreement_id))")));
2507
2508 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_tickets (")
2509 _T("ticket_id integer not null,")
2510 _T("service_id integer not null,")
2511 _T("create_timestamp integer not null,")
2512 _T("close_timestamp integer not null,")
2513 _T("reason varchar(255) not null,")
2514 _T("PRIMARY KEY(ticket_id))")));
2515
2516 CHK_EXEC(CreateTable(_T("CREATE TABLE organizations (")
2517 _T("id integer not null,")
2518 _T("parent_id integer not null,")
2519 _T("org_type integer not null,")
2520 _T("name varchar(63) not null,")
2521 _T("description varchar(255),")
2522 _T("manager integer not null,")
2523 _T("PRIMARY KEY(id))")));
2524
2525 CHK_EXEC(CreateTable(_T("CREATE TABLE persons (")
2526 _T("id integer not null,")
2527 _T("org_id integer not null,")
2528 _T("first_name varchar(63),")
2529 _T("last_name varchar(63),")
2530 _T("title varchar(255),")
2531 _T("status integer not null,")
2532 _T("PRIMARY KEY(id))")));
2533
2534 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='233' WHERE var_name='SchemaVersion'")));
2535 return TRUE;
2536}
2537
2538
8f245200
VK
2539//
2540// Upgrade from V231 to V232
2541//
2542
2543static BOOL H_UpgradeFromV231(int currVersion, int newVersion)
2544{
6f33021d 2545 static TCHAR batch[] =
8f245200
VK
2546 _T("ALTER TABLE object_properties ADD submap_id integer\n")
2547 _T("UPDATE object_properties SET submap_id=0\n")
2548 _T("DROP TABLE maps\n")
2549 _T("DROP TABLE map_access_lists\n")
2550 _T("DROP TABLE submaps\n")
2551 _T("DROP TABLE submap_object_positions\n")
2552 _T("DROP TABLE submap_links\n")
2553 _T("<END>");
2554
2555 CHK_EXEC(SQLBatch(batch));
2556
2557 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='232' WHERE var_name='SchemaVersion'")));
2558 return TRUE;
2559}
2560
2561
3eab63f2
VK
2562//
2563// Upgrade from V230 to V231
2564//
2565
2566static BOOL H_UpgradeFromV230(int currVersion, int newVersion)
2567{
6f33021d 2568 static TCHAR batch[] =
3eab63f2
VK
2569 _T("ALTER TABLE nodes ADD bridge_base_addr varchar(15)\n")
2570 _T("UPDATE nodes SET bridge_base_addr='000000000000'\n")
2571 _T("<END>");
2572
2573 CHK_EXEC(SQLBatch(batch));
2574
2575 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='231' WHERE var_name='SchemaVersion'")));
2576 return TRUE;
2577}
2578
2579
fceea457
VK
2580//
2581// Upgrade from V229 to V230
2582//
2583
2584static BOOL H_UpgradeFromV229(int currVersion, int newVersion)
2585{
6f33021d 2586 static TCHAR batch1[] =
1a74dc37
VK
2587 _T("ALTER TABLE network_maps ADD bg_latitude varchar(20)\n")
2588 _T("ALTER TABLE network_maps ADD bg_longitude varchar(20)\n")
2589 _T("ALTER TABLE network_maps ADD bg_zoom integer\n")
fceea457
VK
2590 _T("ALTER TABLE dashboard_elements ADD layout_data $SQL:TEXT\n")
2591 _T("<END>");
2592
2593 CHK_EXEC(SQLBatch(batch1));
2594
2595 DB_RESULT hResult = SQLSelect(_T("SELECT dashboard_id,element_id,horizontal_span,vertical_span,horizontal_alignment,vertical_alignment FROM dashboard_elements"));
2596 if (hResult != NULL)
2597 {
2598 TCHAR query[1024], xml[1024];
2599
2600 int count = DBGetNumRows(hResult);
2601 for(int i = 0; i < count; i++)
2602 {
2603 _sntprintf(xml, 1024, _T("<layout><horizontalSpan>%d</horizontalSpan><verticalSpan>%d</verticalSpan><horizontalAlignment>%d</horizontalAlignment><verticalAlignment>%d</verticalAlignment></layout>"),
2604 (int)DBGetFieldLong(hResult, i, 2), (int)DBGetFieldLong(hResult, i, 3),
2605 (int)DBGetFieldLong(hResult, i, 4), (int)DBGetFieldLong(hResult, i, 5));
2606 _sntprintf(query, 1024, _T("UPDATE dashboard_elements SET layout_data=%s WHERE dashboard_id=%d AND element_id=%d"),
2607 (const TCHAR *)DBPrepareString(g_hCoreDB, xml), (int)DBGetFieldLong(hResult, i, 0), (int)DBGetFieldLong(hResult, i, 1));
2608 CHK_EXEC(SQLQuery(query));
2609 }
2610 DBFreeResult(hResult);
2611 }
2612 else
2613 {
2614 if (!g_bIgnoreErrors)
2615 return FALSE;
2616 }
2617
6f33021d 2618 static TCHAR batch2[] =
fceea457
VK
2619 _T("ALTER TABLE dashboard_elements DROP COLUMN horizontal_span\n")
2620 _T("ALTER TABLE dashboard_elements DROP COLUMN vertical_span\n")
2621 _T("ALTER TABLE dashboard_elements DROP COLUMN horizontal_alignment\n")
2622 _T("ALTER TABLE dashboard_elements DROP COLUMN vertical_alignment\n")
2623 _T("<END>");
2624
2625 CHK_EXEC(SQLBatch(batch2));
2626
2627 CreateConfigParam(_T("TileServerURL"), _T("http://tile.openstreetmap.org/"), 1, 0);
2628
2629 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='230' WHERE var_name='SchemaVersion'")));
2630 return TRUE;
2631}
2632
2633
926e8ce7
VK
2634//
2635// Upgrade from V228 to V229
2636//
2637
2638static BOOL H_UpgradeFromV228(int currVersion, int newVersion)
2639{
2640 CHK_EXEC(CreateTable(_T("CREATE TABLE dashboards (")
2641 _T(" id integer not null,")
2642 _T(" num_columns integer not null,")
2643 _T(" PRIMARY KEY(id))")));
2644
2645 CHK_EXEC(CreateTable(_T("CREATE TABLE dashboard_elements (")
2646 _T(" dashboard_id integer not null,")
2647 _T(" element_id integer not null,")
2648 _T(" element_type integer not null,")
2649 _T(" element_data $SQL:TEXT null,")
2650 _T(" horizontal_span integer not null,")
2651 _T(" vertical_span integer not null,")
2652 _T(" horizontal_alignment integer not null,")
2653 _T(" vertical_alignment integer not null,")
2654 _T(" PRIMARY KEY(dashboard_id,element_id))")));
2655
2656 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='229' WHERE var_name='SchemaVersion'")));
2657 return TRUE;
2658}
2659
badf9a95
VK
2660/**
2661 * Upgrade from V227 to V228
2662 */
7a41a06e
VK
2663static BOOL H_UpgradeFromV227(int currVersion, int newVersion)
2664{
2665 CHK_EXEC(SQLQuery(_T("DROP TABLE web_maps")));
2666 CHK_EXEC(MigrateMaps());
2667 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='228' WHERE var_name='SchemaVersion'")));
2668 return TRUE;
2669}
2670
badf9a95
VK
2671/**
2672 * Upgrade from V226 to V227
2673 */
89135050
VK
2674static BOOL H_UpgradeFromV226(int currVersion, int newVersion)
2675{
6f33021d 2676 static TCHAR batch[] =
89135050
VK
2677 _T("ALTER TABLE clusters ADD zone_guid integer\n")
2678 _T("UPDATE clusters SET zone_guid=0\n")
2679 _T("<END>");
2680
2681 CHK_EXEC(SQLBatch(batch));
2682
2683 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='227' WHERE var_name='SchemaVersion'")));
2684 return TRUE;
2685}
2686
2687
4c16cdc7
VK
2688//
2689// Upgrade from V225 to V226
2690//
2691
2692static BOOL H_UpgradeFromV225(int currVersion, int newVersion)
2693{
6f33021d 2694 static TCHAR batch[] =
4c16cdc7
VK
2695 _T("ALTER TABLE interfaces ADD flags integer\n")
2696 _T("UPDATE interfaces SET flags=0\n")
2697 _T("UPDATE interfaces SET flags=1 WHERE synthetic_mask<>0\n")
2698 _T("ALTER TABLE interfaces DROP COLUMN synthetic_mask\n")
2699 _T("<END>");
2700
2701 CHK_EXEC(SQLBatch(batch));
2702
2703 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='226' WHERE var_name='SchemaVersion'")));
2704 return TRUE;
2705}
2706
2707
478d4ff4
VK
2708//
2709// Upgrade from V224 to V225
2710//
2711
2712static BOOL H_UpgradeFromV224(int currVersion, int newVersion)
2713{
6f33021d 2714 static TCHAR batch[] =
478d4ff4
VK
2715 _T("ALTER TABLE interfaces ADD description varchar(255)\n")
2716 _T("UPDATE interfaces SET description=''\n")
2717 _T("<END>");
2718
2719 CHK_EXEC(SQLBatch(batch));
2720
2721 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='225' WHERE var_name='SchemaVersion'")));
2722 return TRUE;
2723}
2724
badf9a95
VK
2725/**
2726 * Upgrade from V223 to V224
2727 */
52c31148
VK
2728static BOOL H_UpgradeFromV223(int currVersion, int newVersion)
2729{
6f33021d 2730 static TCHAR batch[] =
52c31148
VK
2731 _T("DROP TABLE zone_ip_addr_list\n")
2732 _T("ALTER TABLE zones DROP COLUMN zone_type\n")
2733 _T("ALTER TABLE zones DROP COLUMN controller_ip\n")
2734 _T("ALTER TABLE zones ADD agent_proxy integer\n")
2735 _T("ALTER TABLE zones ADD snmp_proxy integer\n")
2736 _T("ALTER TABLE zones ADD icmp_proxy integer\n")
2737 _T("UPDATE zones SET agent_proxy=0,snmp_proxy=0,icmp_proxy=0\n")
2738 _T("<END>");
2739
2740 CHK_EXEC(SQLBatch(batch));
2741
2742 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='224' WHERE var_name='SchemaVersion'")));
2743 return TRUE;
2744}
2745
badf9a95
VK
2746/**
2747 * Upgrade from V222 to V223
2748 */
5ad2167d
VK
2749static BOOL H_UpgradeFromV222(int currVersion, int newVersion)
2750{
6f33021d 2751 static TCHAR batch[] =
5ad2167d
VK
2752 _T("DROP TABLE oid_to_type\n")
2753 _T("ALTER TABLE nodes DROP COLUMN node_type\n")
2754 _T("ALTER TABLE nodes ADD primary_name varchar(255)\n")
2755 _T("UPDATE nodes SET primary_name=primary_ip\n")
2756 _T("<END>");
2757
2758 CHK_EXEC(SQLBatch(batch));
2759
2760 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='223' WHERE var_name='SchemaVersion'")));
2761 return TRUE;
2762}
2763
2764
465b3f2d 2765//
f25b0d12
VK
2766// Upgrade from V221 to V222
2767//
2768
2769static BOOL H_UpgradeFromV221(int currVersion, int newVersion)
2770{
6f33021d 2771 static TCHAR batch[] =
f25b0d12
VK
2772 _T("ALTER TABLE object_properties ADD image varchar(36)\n")
2773 _T("UPDATE object_properties SET image='00000000-0000-0000-0000-000000000000'\n")
2774 _T("<END>");
2775
2776 CHK_EXEC(SQLBatch(batch));
2777
2778 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='222' WHERE var_name='SchemaVersion'")));
2779 return TRUE;
2780}
2781
2782
2783//
2784// Upgrade from V220 to V221
465b3f2d
VK
2785//
2786
2787static BOOL H_UpgradeFromV220(int currVersion, int newVersion)
2788{
6f33021d 2789 static TCHAR batch[] =
465b3f2d
VK
2790 _T("ALTER TABLE network_maps DROP COLUMN background\n")
2791 _T("ALTER TABLE network_maps ADD background varchar(36)\n")
2792 _T("<END>");
2793
2794 CHK_EXEC(SQLBatch(batch));
2795
2796 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='221' WHERE var_name='SchemaVersion'")));
2797 return TRUE;
2798}
2799
2800
d74c80ea
VK
2801//
2802// Upgrade from V219 to V220
2803//
2804
2805static BOOL H_UpgradeFromV219(int currVersion, int newVersion)
2806{
6f33021d 2807 static TCHAR batch[] =
d74c80ea
VK
2808 _T("ALTER TABLE interfaces ADD bridge_port integer\n")
2809 _T("ALTER TABLE interfaces ADD phy_slot integer\n")
2810 _T("ALTER TABLE interfaces ADD phy_port integer\n")
2811 _T("ALTER TABLE interfaces ADD peer_node_id integer\n")
2812 _T("ALTER TABLE interfaces ADD peer_if_id integer\n")
2813 _T("UPDATE interfaces SET bridge_port=0,phy_slot=0,phy_port=0,peer_node_id=0,peer_if_id=0\n")
2814 _T("ALTER TABLE nodes ADD snmp_sys_name varchar(127)\n")
2815 _T("UPDATE nodes SET snmp_sys_name=''\n")
2816 _T("<END>");
2817
2818 CHK_EXEC(SQLBatch(batch));
2819
2820 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='220' WHERE var_name='SchemaVersion'")));
2821 return TRUE;
2822}
2823
2824
e6b9439a
AK
2825//
2826// Upgrade from V218 to V219
2827//
2828
2829static BOOL H_UpgradeFromV218(int currVersion, int newVersion)
2830{
2831 CHK_EXEC(CreateTable(_T("CREATE TABLE images (")
9cd5201a
AK
2832 _T(" guid varchar(36) not null,")
2833 _T(" mimetype varchar(64) not null,")
2834 _T(" name varchar(255) not null,")
e6b9439a
AK
2835 _T(" category varchar(255) not null,")
2836 _T(" protected integer default 0,")
2837 _T(" ")
9cd5201a
AK
2838 _T(" PRIMARY KEY(guid),")
2839 _T(" UNIQUE(name, category))")));
2840
2841 static TCHAR batch[] =
2842 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2843 _T("('1ddb76a3-a05f-4a42-acda-22021768feaf', 'image/png', 'ATM', 'Network Objects', 1)\n")
9cd5201a 2844 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2845 _T("('b314cf44-b2aa-478e-b23a-73bc5bb9a624', 'image/png', 'HSM', 'Network Objects', 1)\n")
9cd5201a 2846 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2847 _T("('904e7291-ee3f-41b7-8132-2bd29288ecc8', 'image/png', 'Node', 'Network Objects', 1)\n")
9cd5201a 2848 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2849 _T("('f5214d16-1ab1-4577-bb21-063cfd45d7af', 'image/png', 'Printer', 'Network Objects', 1)\n")
9cd5201a 2850 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2851 _T("('bacde727-b183-4e6c-8dca-ab024c88b999', 'image/png', 'Router', 'Network Objects', 1)\n")
9cd5201a 2852 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2853 _T("('ba6ab507-f62d-4b8f-824c-ca9d46f22375', 'image/png', 'Server', 'Network Objects', 1)\n")
9cd5201a 2854 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2855 _T("('092e4b35-4e7c-42df-b9b7-d5805bfac64e', 'image/png', 'Service', 'Network Objects', 1)\n")
9cd5201a 2856 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2857 _T("('f9105c54-8dcf-483a-b387-b4587dfd3cba', 'image/png', 'Switch', 'Network Objects', 1)\n")
9cd5201a 2858 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2859 _T("('7cd999e9-fbe0-45c3-a695-f84523b3a50c', 'image/png', 'Unknown', 'Network Objects', 1)\n")
9cd5201a
AK
2860 _T("<END>");
2861
2862 CHK_EXEC(SQLBatch(batch));
e6b9439a
AK
2863
2864 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='219' WHERE var_name='SchemaVersion'")));
2865 return TRUE;
2866}
2867
480e036b
VK
2868/**
2869 * Upgrade from V217 to V218
2870 */
4fe87cdc
VK
2871static BOOL H_UpgradeFromV217(int currVersion, int newVersion)
2872{
480e036b 2873 CHK_EXEC(SetColumnNullable(_T("snmp_communities"), _T("community")));
4fe87cdc
VK
2874 CHK_EXEC(ConvertStrings(_T("snmp_communities"), _T("id"), _T("community")));
2875
2876 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='218' WHERE var_name='SchemaVersion'")));
2877 return TRUE;
2878}
2879
480e036b
VK
2880/**
2881 * Upgrade from V216 to V217
2882 */
65e2005b
VK
2883static BOOL H_UpgradeFromV216(int currVersion, int newVersion)
2884{
6f33021d 2885 static TCHAR batch[] =
65e2005b 2886 _T("ALTER TABLE nodes ADD snmp_port integer\n")
8cad4ebb 2887 _T("UPDATE nodes SET snmp_port=161\n")
65e2005b
VK
2888 _T("ALTER TABLE items ADD snmp_port integer\n")
2889 _T("UPDATE items SET snmp_port=0\n")
2890 _T("<END>");
2891
2892 CHK_EXEC(SQLBatch(batch));
2893
480e036b 2894 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("community")));
65e2005b
VK
2895 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("community")));
2896
480e036b 2897 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("usm_auth_password")));
65e2005b
VK
2898 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("usm_auth_password")));
2899
480e036b 2900 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("usm_priv_password")));
65e2005b
VK
2901 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("usm_priv_password")));
2902
480e036b 2903 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("snmp_oid")));
65e2005b
VK
2904 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("snmp_oid")));
2905
480e036b 2906 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("secret")));
65e2005b
VK
2907 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("secret")));
2908
480e036b 2909 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("agent_version")));
65e2005b
VK
2910 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("agent_version")));
2911
480e036b 2912 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("platform_name")));
65e2005b
VK
2913 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("platform_name")));
2914
480e036b 2915 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("uname")));
65e2005b
VK
2916 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("uname")));
2917
480e036b 2918 CHK_EXEC(SetColumnNullable(_T("items"), _T("name")));
65e2005b
VK
2919 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("name")));
2920
480e036b 2921 CHK_EXEC(SetColumnNullable(_T("items"), _T("description")));
65e2005b
VK
2922 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("description")));
2923
480e036b 2924 CHK_EXEC(SetColumnNullable(_T("items"), _T("transformation")));
65e2005b
VK
2925 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("transformation")));
2926
480e036b 2927 CHK_EXEC(SetColumnNullable(_T("items"), _T("instance")));
65e2005b
VK
2928 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("instance")));
2929
2930 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='217' WHERE var_name='SchemaVersion'")));
2931 return TRUE;
2932}
2933
480e036b
VK
2934/**
2935 * Upgrade from V215 to V216
2936 */
3f7c0fe4
VK
2937static BOOL H_UpgradeFromV215(int currVersion, int newVersion)
2938{
480e036b 2939 CHK_EXEC(SetColumnNullable(_T("ap_common"), _T("description")));
3f7c0fe4
VK
2940 CHK_EXEC(ConvertStrings(_T("ap_common"), _T("id"), _T("description")));
2941
a6c1f07f
VK
2942 if (g_iSyntax != DB_SYNTAX_SQLITE)
2943 CHK_EXEC(SQLQuery(_T("ALTER TABLE ap_config_files DROP COLUMN file_name")));
2944
480e036b 2945 CHK_EXEC(SetColumnNullable(_T("ap_config_files"), _T("file_content")));
a30fa363
VK
2946 CHK_EXEC(ConvertStrings(_T("ap_config_files"), _T("policy_id"), _T("file_content")));
2947
3f7c0fe4
VK
2948 CHK_EXEC(SQLQuery(_T("ALTER TABLE object_properties ADD guid varchar(36)")));
2949
2950 // Generate GUIDs for all objects
2951 DB_RESULT hResult = SQLSelect(_T("SELECT object_id FROM object_properties"));
2952 if (hResult != NULL)
2953 {
2954 int count = DBGetNumRows(hResult);
2955 for(int i = 0; i < count; i++)
2956 {
2957 uuid_t guid;
2958 TCHAR query[256], buffer[64];
2959
2960 uuid_generate(guid);
2961 _sntprintf(query, 256, _T("UPDATE object_properties SET guid='%s' WHERE object_id=%d"),
2962 uuid_to_string(guid, buffer), DBGetFieldULong(hResult, i, 0));
2963 CHK_EXEC(SQLQuery(query));
2964 }
2965 DBFreeResult(hResult);
2966 }
6f33021d 2967
3f7c0fe4
VK
2968 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='216' WHERE var_name='SchemaVersion'")));
2969 return TRUE;
2970}
2971
2972
021dcda7
VK
2973//
2974// Upgrade from V214 to V215
2975//
2976
2977static BOOL H_UpgradeFromV214(int currVersion, int newVersion)
2978{
2979 CHK_EXEC(CreateTable(_T("CREATE TABLE network_maps (")
2980 _T("id integer not null,")
2981 _T("map_type integer not null,")
2982 _T("layout integer not null,")
2983 _T("seed integer not null,")
2984 _T("background integer not null,")
2985 _T("PRIMARY KEY(id))")));
2986
2987 CHK_EXEC(CreateTable(_T("CREATE TABLE network_map_elements (")
2988 _T("map_id integer not null,")
2989 _T("element_id integer not null,")
2990 _T("element_type integer not null,")
2991 _T("element_data $SQL:TEXT not null,")
2992 _T("PRIMARY KEY(map_id,element_id))")));
2993
cce8f214
VK
2994 CHK_EXEC(CreateTable(_T("CREATE TABLE network_map_links (")
2995 _T("map_id integer not null,")
2996 _T("element1 integer not null,")
2997 _T("element2 integer not null,")
2998 _T("link_type integer not null,")
2999 _T("link_name varchar(255) null,")
3000 _T("connector_name1 varchar(255) null,")
3001 _T("connector_name2 varchar(255) null,")
3002 _T("PRIMARY KEY(map_id,element1,element2))")));
3003
021dcda7
VK
3004 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='215' WHERE var_name='SchemaVersion'")));
3005 return TRUE;
3006}
3007
480e036b
VK
3008/**
3009 * Upgrade from V213 to V214
3010 */
50da2d20
VK
3011static BOOL H_UpgradeFromV213(int currVersion, int newVersion)
3012{
480e036b 3013 CHK_EXEC(SetColumnNullable(_T("script_library"), _T("script_code")));
50da2d20
VK
3014 CHK_EXEC(ConvertStrings(_T("script_library"), _T("script_id"), _T("script_code")));
3015
480e036b 3016 CHK_EXEC(SetColumnNullable(_T("raw_dci_values"), _T("raw_value")));
50da2d20
VK
3017 CHK_EXEC(ConvertStrings(_T("raw_dci_values"), _T("item_id"), _T("raw_value")));
3018
3019 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'")));
3020
3021 DB_RESULT hResult = SQLSelect(_T("SELECT id FROM nodes"));
3022 if (hResult != NULL)
3023 {
3024 int count = DBGetNumRows(hResult);
3025 for(int i = 0; i < count; i++)
3026 {
3027 TCHAR table[32];
3028
3029 DWORD nodeId = DBGetFieldULong(hResult, i, 0);
3030 _sntprintf(table, 32, _T("idata_%d"), nodeId);
480e036b 3031 CHK_EXEC(SetColumnNullable(table, _T("idata_value")));
50da2d20
VK
3032 }
3033 DBFreeResult(hResult);
3034 }
3035
3036 // Convert values for string DCIs from # encoded to normal form
3037 hResult = SQLSelect(_T("SELECT node_id,item_id FROM items WHERE datatype=4"));
3038 if (hResult != NULL)
3039 {
3040 int count = DBGetNumRows(hResult);
3041 for(int i = 0; i < count; i++)
3042 {
3043 TCHAR query[512];
3044
3045 DWORD nodeId = DBGetFieldULong(hResult, i, 0);
3046 DWORD dciId = DBGetFieldULong(hResult, i, 1);
3047
035a4d73 3048 if (IsNodeExist(nodeId))
50da2d20 3049 {
3f7c0fe4 3050 _sntprintf(query, 512, _T("SELECT idata_timestamp,idata_value FROM idata_%d WHERE item_id=%d AND idata_value LIKE '%%#%%'"), nodeId, dciId);
035a4d73
VK
3051 DB_RESULT hData = SQLSelect(query);
3052 if (hData != NULL)
50da2d20 3053 {
035a4d73
VK
3054 int valueCount = DBGetNumRows(hData);
3055 for(int j = 0; j < valueCount; j++)
3056 {
3057 TCHAR buffer[MAX_DB_STRING];
3058
3059 LONG ts = DBGetFieldLong(hData, j, 0);
3060 DBGetField(hData, j, 1, buffer, MAX_DB_STRING);
3f7c0fe4
VK
3061 DecodeSQLString(buffer);
3062
3063 _sntprintf(query, 512, _T("UPDATE idata_%d SET idata_value=%s WHERE item_id=%d AND idata_timestamp=%ld"),
3064 nodeId, (const TCHAR *)DBPrepareString(g_hCoreDB, buffer), dciId, (long)ts);
3065 CHK_EXEC(SQLQuery(query));
035a4d73
VK
3066 }
3067 DBFreeResult(hData);
50da2d20 3068 }
50da2d20
VK
3069 }
3070 }
3071 DBFreeResult(hResult);
3072 }
3073
3074 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='214' WHERE var_name='SchemaVersion'")));
50da2d20
VK
3075 return TRUE;
3076}
3077
480e036b
VK
3078/**
3079 * Upgrade from V212 to V213
3080 */
f57209fd
VK
3081static BOOL H_UpgradeFromV212(int currVersion, int newVersion)
3082{
480e036b
VK
3083 CHK_EXEC(SetColumnNullable(_T("items"), _T("custom_units_name")));
3084 CHK_EXEC(SetColumnNullable(_T("items"), _T("perftab_settings")));
f57209fd
VK
3085
3086 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("custom_units_name")));
3087 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("perftab_settings")));
3088
3089 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='213' WHERE var_name='SchemaVersion'")));
3090
3091 return TRUE;
3092}
3093
480e036b
VK
3094/**
3095 * Upgrade from V211 to V212
3096 */
1024e962
VK
3097static BOOL H_UpgradeFromV211(int currVersion, int newVersion)
3098{
480e036b
VK
3099 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("snmp_oid")));
3100 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("user_tag")));
3101 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("description")));
1024e962
VK
3102
3103 CHK_EXEC(ConvertStrings(_T("snmp_trap_cfg"), _T("trap_id"), _T("user_tag")));
3104 CHK_EXEC(ConvertStrings(_T("snmp_trap_cfg"), _T("trap_id"), _T("description")));
3105
3106 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='212' WHERE var_name='SchemaVersion'")));
3107
3108 return TRUE;
3109}
3110
480e036b
VK
3111/**
3112 * Upgrade from V210 to V211
3113 */
a8f60046
VK
3114static BOOL H_UpgradeFromV210(int currVersion, int newVersion)
3115{
6f33021d 3116 static TCHAR batch[] =
a8f60046
VK
3117 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
3118 _T(" (53,'SYS_DCI_UNSUPPORTED',2,1,'Status of DCI %1 (%5: %2) changed to UNSUPPORTED',")
3119 _T("'Generated when DCI status changed to UNSUPPORTED.#0D#0AParameters:#0D#0A")
3120 _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")
3121 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
3122 _T(" (54,'SYS_DCI_DISABLED',1,1,'Status of DCI %1 (%5: %2) changed to DISABLED',")
3123 _T("'Generated when DCI status changed to DISABLED.#0D#0AParameters:#0D#0A")
3124 _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")
3125 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
3126 _T(" (55,'SYS_DCI_ACTIVE',0,1,'Status of DCI %1 (%5: %2) changed to ACTIVE',")
3127 _T("'Generated when DCI status changed to ACTIVE.#0D#0AParameters:#0D#0A")
3128 _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")
3129 _T("<END>");
3130
1024e962
VK
3131 CHK_EXEC(SQLBatch(batch));
3132 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='211' WHERE var_name='SchemaVersion'")));
a8f60046
VK
3133
3134 return TRUE;
3135}
3136
85ae39bc
VK
3137/**
3138 * Upgrade from V209 to V210
3139 */
43c1be79
VK
3140static BOOL H_UpgradeFromV209(int currVersion, int newVersion)
3141{
3142 if (!SQLQuery(_T("DELETE FROM metadata WHERE var_name like 'IDataIndexCreationCommand_%'")))
3143 if (!g_bIgnoreErrors)
3144 return FALSE;
3145
3146 const TCHAR *query;
3147 switch(g_iSyntax)
3148 {
3149 case DB_SYNTAX_PGSQL:
3150 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)')");
3151 break;
3152 case DB_SYNTAX_MSSQL:
3153 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)')");
3154 break;
3155 default:
3156 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)')");
3157 break;
3158 }
3159
3160 if (!SQLQuery(query))
3161 if (!g_bIgnoreErrors)
3162 return FALSE;
3163
3164 ReindexIData();
3165
3166 if (!SQLQuery(_T("UPDATE metadata SET var_value='210' WHERE var_name='SchemaVersion'")))
3167 if (!g_bIgnoreErrors)
3168 return FALSE;
3169
3170 return TRUE;
3171}
3172
7541bca2
VK
3173/**
3174 * Upgrade from V208 to V209
3175 */
ab185583
VK
3176static BOOL H_UpgradeFromV208(int currVersion, int newVersion)
3177{
6f33021d 3178 static TCHAR batch[] =
ab185583
VK
3179 _T("ALTER TABLE users ADD auth_failures integer\n")
3180 _T("ALTER TABLE users ADD last_passwd_change integer\n")
3181 _T("ALTER TABLE users ADD min_passwd_length integer\n")
3182 _T("ALTER TABLE users ADD disabled_until integer\n")
3183 _T("ALTER TABLE users ADD last_login integer\n")
3184 _T("ALTER TABLE users ADD password_history $SQL:TEXT\n")
3185 _T("UPDATE users SET auth_failures=0,last_passwd_change=0,min_passwd_length=-1,disabled_until=0,last_login=0\n")
3186 _T("<END>");
3187
3188 if (!SQLBatch(batch))
3189 if (!g_bIgnoreErrors)
3190 return FALSE;
3191
3192 if (!CreateConfigParam(_T("PasswordHistoryLength"), _T("0"), 1, 0))
3193 if (!g_bIgnoreErrors)
3194 return FALSE;
3195
0f1ddb74 3196 if (!CreateConfigParam(_T("IntruderLockoutThreshold"), _T("0"), 1, 0))
ab185583
VK
3197 if (!g_bIgnoreErrors)
3198 return FALSE;
3199
3200 if (!CreateConfigParam(_T("IntruderLockoutTime"), _T("30"), 1, 0))
3201 if (!g_bIgnoreErrors)
3202 return FALSE;
3203
3204 if (!CreateConfigParam(_T("MinPasswordLength"), _T("0"), 1, 0))
3205 if (!g_bIgnoreErrors)
3206 return FALSE;
3207
3208 if (!CreateConfigParam(_T("PasswordComplexity"), _T("0"), 1, 0))
3209 if (!g_bIgnoreErrors)
3210 return FALSE;
3211
3212 if (!CreateConfigParam(_T("PasswordExpiration"), _T("0"), 1, 0))
3213 if (!g_bIgnoreErrors)
3214 return FALSE;
3215
3216 if (!CreateConfigParam(_T("BlockInactiveUserAccounts"), _T("0"), 1, 0))
3217 if (!g_bIgnoreErrors)
3218 return FALSE;
3219
3220 if (!SQLQuery(_T("UPDATE metadata SET var_value='209' WHERE var_name='SchemaVersion'")))
3221 if (!g_bIgnoreErrors)
3222 return FALSE;
3223
3224 return TRUE;
3225}
3226
3227
80d3565a
VK
3228//
3229// Upgrade from V207 to V208
3230//
3231
3232static BOOL H_UpgradeFromV207(int currVersion, int newVersion)
3233{
3234 if (!SQLQuery(_T("ALTER TABLE items ADD system_tag varchar(255)")))
3235 if (!g_bIgnoreErrors)
3236 return FALSE;
3237
3238 if (!SQLQuery(_T("UPDATE metadata SET var_value='208' WHERE var_name='SchemaVersion'")))
3239 if (!g_bIgnoreErrors)
3240 return FALSE;
3241
3242 return TRUE;
3243}
3244
3245
5ab2f1ab
VK
3246//
3247// Upgrade from V206 to V207
3248//
3249
3250static BOOL H_UpgradeFromV206(int currVersion, int newVersion)
3251{
3252 if (!CreateConfigParam(_T("RADIUSSecondaryServer"), _T("none"), 1, 0))
3253 if (!g_bIgnoreErrors)
3254 return FALSE;
3255
3256 if (!CreateConfigParam(_T("RADIUSSecondarySecret"), _T("netxms"), 1, 0))
3257 if (!g_bIgnoreErrors)
3258 return FALSE;
3259
3260 if (!CreateConfigParam(_T("RADIUSSecondaryPort"), _T("1645"), 1, 0))
3261 if (!g_bIgnoreErrors)
3262 return FALSE;
3263
3264 if (!CreateConfigParam(_T("ExternalAuditServer"), _T("none"), 1, 1))
3265 if (!g_bIgnoreErrors)
3266 return FALSE;
3267
3268 if (!CreateConfigParam(_T("ExternalAuditPort"), _T("514"), 1, 1))
3269 if (!g_bIgnoreErrors)
3270 return FALSE;
3271
3272 if (!CreateConfigParam(_T("ExternalAuditFacility"), _T("13"), 1, 1))
3273 if (!g_bIgnoreErrors)
3274 return FALSE;
3275
3276 if (!CreateConfigParam(_T("ExternalAuditSeverity"), _T("5"), 1, 1))
3277 if (!g_bIgnoreErrors)
3278 return FALSE;
3279
3280 if (!CreateConfigParam(_T("ExternalAuditTag"), _T("netxmsd-audit"), 1, 1))
3281 if (!g_bIgnoreErrors)
3282 return FALSE;
3283
3284 if (!SQLQuery(_T("UPDATE metadata SET var_value='207' WHERE var_name='SchemaVersion'")))
3285 if (!g_bIgnoreErrors)
3286 return FALSE;
3287
3288 return TRUE;
3289}
3290
3291
ce7565e7
VK
3292//
3293// Upgrade from V205 to V206
3294//
3295
3296static BOOL H_UpgradeFromV205(int currVersion, int newVersion)
3297{
a4743a0f
VK
3298 if (g_iSyntax == DB_SYNTAX_ORACLE)
3299 {
3300 static TCHAR oraBatch[] =
3301 _T("ALTER TABLE audit_log MODIFY message null\n")
3302 _T("ALTER TABLE event_log MODIFY event_message null\n")
3303 _T("ALTER TABLE event_log MODIFY user_tag null\n")
3304 _T("ALTER TABLE syslog MODIFY hostname null\n")
3305 _T("ALTER TABLE syslog MODIFY msg_tag null\n")
3306 _T("ALTER TABLE syslog MODIFY msg_text null\n")
3307 _T("ALTER TABLE snmp_trap_log MODIFY trap_varlist null\n")
3308 _T("<END>");
3309
3310 if (!SQLBatch(oraBatch))
3311 if (!g_bIgnoreErrors)
3312 return FALSE;
3313 }
ce7565e7 3314
a4743a0f
VK
3315 bool clearLogs = GetYesNo(_T("This database upgrade requires log conversion. This can take significant amount of time ")
3316 _T("(up to few hours for large databases). If preserving all log records is not very important, it is ")
3317 _T("recommended to clear logs befor conversion. Clear logs?"));
ce7565e7 3318
a4743a0f
VK
3319 if (clearLogs)
3320 {
3321 if (!SQLQuery(_T("DELETE FROM audit_log")))
3322 if (!g_bIgnoreErrors)
3323 return FALSE;
ce7565e7 3324
a4743a0f
VK
3325 if (!SQLQuery(_T("DELETE FROM event_log")))
3326 if (!g_bIgnoreErrors)
3327 return FALSE;
3328
3329 if (!SQLQuery(_T("DELETE FROM syslog")))
3330 if (!g_bIgnoreErrors)
3331 return FALSE;
3332
3333 if (!SQLQuery(_T("DELETE FROM snmp_trap_log")))
3334 if (!g_bIgnoreErrors)
3335 return FALSE;
3336 }
3337 else
3338 {
3339 // Convert event log
08b214c6 3340 if (!ConvertStrings(_T("event_log"), _T("event_id"), _T("event_message")))
a4743a0f
VK
3341 if (!g_bIgnoreErrors)
3342 return FALSE;
08b214c6 3343 if (!ConvertStrings(_T("event_log"), _T("event_id"), _T("user_tag")))
a4743a0f
VK
3344 if (!g_bIgnoreErrors)
3345 return FALSE;
3346
3347 // Convert audit log
08b214c6 3348 if (!ConvertStrings(_T("audit_log"), _T("record_id"), _T("message")))
a4743a0f
VK
3349 if (!g_bIgnoreErrors)
3350 return FALSE;
3351
3352 // Convert syslog
08b214c6 3353 if (!ConvertStrings(_T("syslog"), _T("msg_id"), _T("msg_text")))
a4743a0f
VK
3354 if (!g_bIgnoreErrors)
3355 return FALSE;
3356
3357 // Convert SNMP trap log
08b214c6 3358 if (!ConvertStrings(_T("snmp_trap_log"), _T("trap_id"), _T("trap_varlist")))
a4743a0f
VK
3359 if (!g_bIgnoreErrors)
3360 return FALSE;
3361 }
ce7565e7
VK
3362
3363 if (!SQLQuery(_T("UPDATE metadata SET var_value='206' WHERE var_name='SchemaVersion'")))
3364 if (!g_bIgnoreErrors)
3365 return FALSE;
3366
3367 return TRUE;
3368}
3369
3370
df8a4ca2
VK
3371//
3372// Upgrade from V204 to V205
3373//
3374
3375static BOOL H_UpgradeFromV204(int currVersion, int newVersion)
3376{
3377 if (!CreateTable(_T("CREATE TABLE usm_credentials (")
3378 _T("id integer not null,")
3379 _T("user_name varchar(255) not null,")
3380 _T("auth_method integer not null,")
3381 _T("priv_method integer not null,")
3382 _T("auth_password varchar(255),")
3383 _T("priv_password varchar(255),")
3384 _T("PRIMARY KEY(id))")))
3385 if (!g_bIgnoreErrors)
3386 return FALSE;
3387
3388 if (!SQLQuery(_T("UPDATE metadata SET var_value='205' WHERE var_name='SchemaVersion'")))
3389 if (!g_bIgnoreErrors)
3390 return FALSE;
3391
3392 return TRUE;
3393}
3394
3395
e2babedf
VK
3396//
3397// Upgrade from V203 to V204
3398//
3399
3400static BOOL H_UpgradeFromV203(int currVersion, int newVersion)
3401{
6f33021d 3402 static TCHAR batch[] =
e2babedf
VK
3403 _T("ALTER TABLE object_properties ADD location_type integer\n")
3404 _T("ALTER TABLE object_properties ADD latitude varchar(20)\n")
3405 _T("ALTER TABLE object_properties ADD longitude varchar(20)\n")
3406 _T("UPDATE object_properties SET location_type=0\n")
3407 _T("ALTER TABLE object_properties DROP COLUMN image_id\n")
3408 _T("<END>");
3409
3410 if (!SQLBatch(batch))
3411 if (!g_bIgnoreErrors)
3412 return FALSE;
3413
3414 if (!CreateConfigParam(_T("ConnectionPoolBaseSize"), _T("5"), 1, 1))
3415 if (!g_bIgnoreErrors)
3416 return FALSE;
3417
3418 if (!CreateConfigParam(_T("ConnectionPoolMaxSize"), _T("20"), 1, 1))
3419 if (!g_bIgnoreErrors)
3420 return FALSE;
3421
3422 if (!CreateConfigParam(_T("ConnectionPoolCooldownTime"), _T("300"), 1, 1))
3423 if (!g_bIgnoreErrors)
3424 return FALSE;
3425
a4743a0f
VK
3426 if (g_iSyntax == DB_SYNTAX_ORACLE)
3427 {
3428 if (!SQLQuery(_T("ALTER TABLE object_properties MODIFY comments null\n")))
3429 if (!g_bIgnoreErrors)
3430 return FALSE;
3431 }
3432
08b214c6 3433 if (!ConvertStrings(_T("object_properties"), _T("object_id"), _T("comments")))
e2babedf
VK
3434 if (!g_bIgnoreErrors)
3435 return FALSE;
3436
3437 if (!SQLQuery(_T("UPDATE metadata SET var_value='204' WHERE var_name='SchemaVersion'")))
3438 if (!g_bIgnoreErrors)
3439 return FALSE;
3440
3441 return TRUE;
3442}
3443
3444
7cda0d53
VK
3445//
3446// Upgrade from V202 to V203
3447//
3448
3449static BOOL H_UpgradeFromV202(int currVersion, int newVersion)
3450{
6f33021d 3451 static TCHAR batch[] =
7cda0d53
VK
3452 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text)")
3453 _T(" VALUES (20,'&Info->Topology table (LLDP)',2,'Topology Table',1,' ','Show topology table (LLDP)','#00')\n")
3454 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3455 _T(" VALUES (20,0,'Chassis ID','.1.0.8802.1.1.2.1.4.1.1.5',0,0)\n")
3456 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3457 _T(" VALUES (20,1,'Local port','.1.0.8802.1.1.2.1.4.1.1.2',5,0)\n")
3458 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3459 _T(" VALUES (20,2,'System name','.1.0.8802.1.1.2.1.4.1.1.9',0,0)\n")
3460 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3461 _T(" VALUES (20,3,'System description','.1.0.8802.1.1.2.1.4.1.1.10',0,0)\n")
3462 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3463 _T(" VALUES (20,4,'Remote port ID','.1.0.8802.1.1.2.1.4.1.1.7',4,0)\n")
3464 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3465 _T(" VALUES (20,5,'Remote port description','.1.0.8802.1.1.2.1.4.1.1.8',0,0)\n")
3466 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (20,-2147483648)\n")
3467 _T("<END>");
3468
3469 if (!SQLBatch(batch))
3470 if (!g_bIgnoreErrors)
3471 return FALSE;
3472
3473 if (!SQLQuery(_T("UPDATE metadata SET var_value='203' WHERE var_name='SchemaVersion'")))
3474 if (!g_bIgnoreErrors)
3475 return FALSE;
3476
3477 return TRUE;
3478}
3479
3480
643c9dcb
VK
3481//
3482// Upgrade from V201 to V202
3483//
3484
3485static BOOL H_UpgradeFromV201(int currVersion, int newVersion)
3486{
a4743a0f
VK
3487 if (g_iSyntax == DB_SYNTAX_ORACLE)
3488 {
3489 static TCHAR oraBatch[] =
3490 _T("ALTER TABLE alarms MODIFY message null\n")
3491 _T("ALTER TABLE alarms MODIFY alarm_key null\n")
3492 _T("ALTER TABLE alarms MODIFY hd_ref null\n")
3493 _T("<END>");
3494
3495 if (!SQLBatch(oraBatch))
3496 if (!g_bIgnoreErrors)
3497 return FALSE;
3498 }
3499
08b214c6 3500 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("message")))
643c9dcb
VK
3501 if (!g_bIgnoreErrors)
3502 return FALSE;
08b214c6 3503 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("alarm_key")))
643c9dcb
VK
3504 if (!g_bIgnoreErrors)
3505 return FALSE;
08b214c6 3506 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("hd_ref")))
643c9dcb
VK
3507 if (!g_bIgnoreErrors)
3508 return FALSE;
3509
3510 if (!SQLQuery(_T("UPDATE metadata SET var_value='202' WHERE var_name='SchemaVersion'")))
3511 if (!g_bIgnoreErrors)
3512 return FALSE;
3513
3514 return TRUE;
3515}
3516
3517
31cc1924
VK
3518//
3519// Upgrade from V200 to V201
3520//
3521
3522static BOOL H_UpgradeFromV200(int currVersion, int newVersion)
3523{
3524 static TCHAR batch[] =
3525 _T("ALTER TABLE nodes ADD usm_auth_password varchar(127)\n")
3526 _T("ALTER TABLE nodes ADD usm_priv_password varchar(127)\n")
3527 _T("ALTER TABLE nodes ADD usm_methods integer\n")
e8daf6d5 3528 _T("UPDATE nodes SET usm_auth_password='#00',usm_priv_password='#00',usm_methods=0\n")
31cc1924 3529 _T("<END>");
6f33021d 3530
31cc1924
VK
3531 if (!SQLBatch(batch))
3532 if (!g_bIgnoreErrors)