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