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