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