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