Commit | Line | Data |
---|---|---|
5039dede AK |
1 | /* |
2 | ** nxdbmgr - NetXMS database manager | |
3 | ** Copyright (C) 2004, 2005, 2006, 2007, 2008 Victor Kirhenshtein | |
4 | ** | |
5 | ** This program is free software; you can redistribute it and/or modify | |
6 | ** it under the terms of the GNU General Public License as published by | |
7 | ** the Free Software Foundation; either version 2 of the License, or | |
8 | ** (at your option) any later version. | |
9 | ** | |
10 | ** This program is distributed in the hope that it will be useful, | |
11 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | ** GNU General Public License for more details. | |
14 | ** | |
15 | ** You should have received a copy of the GNU General Public License | |
16 | ** along with this program; if not, write to the Free Software | |
17 | ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 | ** | |
19 | ** File: upgrade.cpp | |
20 | ** | |
21 | **/ | |
22 | ||
23 | #include "nxdbmgr.h" | |
24 | ||
25 | ||
26 | // | |
27 | // Create table | |
28 | // | |
29 | ||
30 | static BOOL CreateTable(const TCHAR *pszQuery) | |
31 | { | |
32 | TCHAR *pszBuffer; | |
33 | BOOL bResult; | |
34 | ||
35 | pszBuffer = (TCHAR *)malloc(_tcslen(pszQuery) * sizeof(TCHAR) + 256); | |
36 | _tcscpy(pszBuffer, pszQuery); | |
37 | TranslateStr(pszBuffer, _T("$SQL:TEXT"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]); | |
38 | TranslateStr(pszBuffer, _T("$SQL:INT64"), g_pszSqlType[g_iSyntax][SQL_TYPE_INT64]); | |
39 | if (g_iSyntax == DB_SYNTAX_MYSQL) | |
40 | _tcscat(pszBuffer, g_pszTableSuffix); | |
41 | bResult = SQLQuery(pszBuffer); | |
42 | free(pszBuffer); | |
43 | return bResult; | |
44 | } | |
45 | ||
46 | ||
47 | // | |
48 | // Create configuration parameter if it doesn't exist (unless bForceUpdate set to true) | |
49 | // | |
50 | ||
51 | static BOOL CreateConfigParam(const TCHAR *pszName, const TCHAR *pszValue, | |
52 | int iVisible, int iNeedRestart, BOOL bForceUpdate = FALSE) | |
53 | { | |
54 | TCHAR szQuery[1024], *pszEscValue; | |
55 | DB_RESULT hResult; | |
56 | BOOL bVarExist = FALSE, bResult = TRUE; | |
57 | ||
58 | // Check for variable existence | |
59 | _stprintf(szQuery, _T("SELECT var_value FROM config WHERE var_name='%s'"), pszName); | |
60 | hResult = DBSelect(g_hCoreDB, szQuery); | |
61 | if (hResult != 0) | |
62 | { | |
63 | if (DBGetNumRows(hResult) > 0) | |
64 | bVarExist = TRUE; | |
65 | DBFreeResult(hResult); | |
66 | } | |
67 | ||
68 | if (!bVarExist) | |
69 | { | |
70 | pszEscValue = EncodeSQLString(pszValue); | |
71 | _stprintf(szQuery, _T("INSERT INTO config (var_name,var_value,is_visible,") | |
72 | _T("need_server_restart) VALUES ('%s','%s',%d,%d)"), | |
73 | pszName, pszEscValue, iVisible, iNeedRestart); | |
74 | free(pszEscValue); | |
75 | bResult = SQLQuery(szQuery); | |
76 | } | |
77 | else if (bForceUpdate) | |
78 | { | |
79 | pszEscValue = EncodeSQLString(pszValue); | |
80 | _stprintf(szQuery, _T("UPDATE config SET var_value='%s' WHERE var_name='%s'"), | |
81 | pszEscValue, pszName); | |
82 | free(pszEscValue); | |
83 | bResult = SQLQuery(szQuery); | |
84 | } | |
85 | return bResult; | |
86 | } | |
87 | ||
88 | ||
89 | // | |
90 | // Set primary key constraint | |
91 | // | |
92 | ||
93 | static BOOL SetPrimaryKey(const TCHAR *table, const TCHAR *key) | |
94 | { | |
95 | TCHAR query[4096]; | |
96 | ||
97 | if (g_iSyntax == DB_SYNTAX_SQLITE) | |
98 | return TRUE; // SQLite does not support adding constraints | |
99 | ||
100 | _sntprintf(query, 4096, _T("ALTER TABLE %s ADD PRIMARY KEY (%s)"), table, key); | |
101 | return SQLQuery(query); | |
102 | } | |
103 | ||
104 | ||
643c9dcb | 105 | // |
83f4afe0 | 106 | // Convert strings from # encoded form to normal form |
643c9dcb VK |
107 | // |
108 | ||
109 | static BOOL ConvertStrings(const TCHAR *table, const TCHAR *idColumn, const TCHAR *column) | |
110 | { | |
111 | DB_RESULT hResult; | |
112 | TCHAR *query; | |
113 | int queryLen = 512; | |
114 | BOOL success = FALSE; | |
115 | ||
116 | query = (TCHAR *)malloc(queryLen); | |
fe12a1ea | 117 | |
a4743a0f VK |
118 | switch(g_iSyntax) |
119 | { | |
120 | case DB_SYNTAX_MSSQL: | |
121 | _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE CAST(%s AS nvarchar(max))=N'#00'"), table, column, column); | |
122 | break; | |
123 | case DB_SYNTAX_ORACLE: | |
124 | _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE to_char(%s)='#00'"), table, column, column); | |
125 | break; | |
126 | default: | |
127 | _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE %s='#00'"), table, column, column); | |
128 | break; | |
129 | } | |
fe12a1ea VK |
130 | if (!SQLQuery(query)) |
131 | { | |
132 | free(query); | |
133 | return FALSE; | |
134 | } | |
135 | ||
136 | _sntprintf(query, queryLen, _T("SELECT %s,%s FROM %s WHERE %s LIKE '%%#%%'"), idColumn, column, table, column); | |
643c9dcb VK |
137 | hResult = SQLSelect(query); |
138 | if (hResult == NULL) | |
139 | { | |
140 | free(query); | |
141 | return FALSE; | |
142 | } | |
143 | ||
144 | int count = DBGetNumRows(hResult); | |
145 | for(int i = 0; i < count; i++) | |
146 | { | |
147 | INT64 id = DBGetFieldInt64(hResult, i, 0); | |
148 | TCHAR *value = DBGetField(hResult, i, 1, NULL, 0); | |
149 | DecodeSQLString(value); | |
150 | String newValue = DBPrepareString(value); | |
ce7565e7 | 151 | if ((int)newValue.getSize() + 256 > queryLen) |
643c9dcb | 152 | { |
ce7565e7 | 153 | queryLen = newValue.getSize() + 256; |
643c9dcb VK |
154 | query = (TCHAR *)realloc(query, queryLen); |
155 | } | |
156 | _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=") INT64_FMT, table, column, | |
157 | (const TCHAR *)newValue, idColumn, id); | |
158 | if (!SQLQuery(query)) | |
159 | goto cleanup; | |
160 | } | |
161 | success = TRUE; | |
162 | ||
163 | cleanup: | |
164 | DBFreeResult(hResult); | |
a4743a0f | 165 | free(query); |
643c9dcb VK |
166 | return success; |
167 | } | |
168 | ||
169 | ||
ce7565e7 VK |
170 | // |
171 | // Upgrade from V205 to V206 | |
172 | // | |
173 | ||
174 | static BOOL H_UpgradeFromV205(int currVersion, int newVersion) | |
175 | { | |
a4743a0f VK |
176 | if (g_iSyntax == DB_SYNTAX_ORACLE) |
177 | { | |
178 | static TCHAR oraBatch[] = | |
179 | _T("ALTER TABLE audit_log MODIFY message null\n") | |
180 | _T("ALTER TABLE event_log MODIFY event_message null\n") | |
181 | _T("ALTER TABLE event_log MODIFY user_tag null\n") | |
182 | _T("ALTER TABLE syslog MODIFY hostname null\n") | |
183 | _T("ALTER TABLE syslog MODIFY msg_tag null\n") | |
184 | _T("ALTER TABLE syslog MODIFY msg_text null\n") | |
185 | _T("ALTER TABLE snmp_trap_log MODIFY trap_varlist null\n") | |
186 | _T("<END>"); | |
187 | ||
188 | if (!SQLBatch(oraBatch)) | |
189 | if (!g_bIgnoreErrors) | |
190 | return FALSE; | |
191 | } | |
ce7565e7 | 192 | |
a4743a0f VK |
193 | bool clearLogs = GetYesNo(_T("This database upgrade requires log conversion. This can take significant amount of time ") |
194 | _T("(up to few hours for large databases). If preserving all log records is not very important, it is ") | |
195 | _T("recommended to clear logs befor conversion. Clear logs?")); | |
ce7565e7 | 196 | |
a4743a0f VK |
197 | if (clearLogs) |
198 | { | |
199 | if (!SQLQuery(_T("DELETE FROM audit_log"))) | |
200 | if (!g_bIgnoreErrors) | |
201 | return FALSE; | |
ce7565e7 | 202 | |
a4743a0f VK |
203 | if (!SQLQuery(_T("DELETE FROM event_log"))) |
204 | if (!g_bIgnoreErrors) | |
205 | return FALSE; | |
206 | ||
207 | if (!SQLQuery(_T("DELETE FROM syslog"))) | |
208 | if (!g_bIgnoreErrors) | |
209 | return FALSE; | |
210 | ||
211 | if (!SQLQuery(_T("DELETE FROM snmp_trap_log"))) | |
212 | if (!g_bIgnoreErrors) | |
213 | return FALSE; | |
214 | } | |
215 | else | |
216 | { | |
217 | // Convert event log | |
218 | if (!ConvertStrings("event_log", "event_id", "event_message")) | |
219 | if (!g_bIgnoreErrors) | |
220 | return FALSE; | |
221 | if (!ConvertStrings("event_log", "event_id", "user_tag")) | |
222 | if (!g_bIgnoreErrors) | |
223 | return FALSE; | |
224 | ||
225 | // Convert audit log | |
226 | if (!ConvertStrings("audit_log", "record_id", "message")) | |
227 | if (!g_bIgnoreErrors) | |
228 | return FALSE; | |
229 | ||
230 | // Convert syslog | |
231 | if (!ConvertStrings("syslog", "msg_id", "msg_text")) | |
232 | if (!g_bIgnoreErrors) | |
233 | return FALSE; | |
234 | ||
235 | // Convert SNMP trap log | |
236 | if (!ConvertStrings("snmp_trap_log", "trap_id", "trap_varlist")) | |
237 | if (!g_bIgnoreErrors) | |
238 | return FALSE; | |
239 | } | |
ce7565e7 VK |
240 | |
241 | if (!SQLQuery(_T("UPDATE metadata SET var_value='206' WHERE var_name='SchemaVersion'"))) | |
242 | if (!g_bIgnoreErrors) | |
243 | return FALSE; | |
244 | ||
245 | return TRUE; | |
246 | } | |
247 | ||
248 | ||
df8a4ca2 VK |
249 | // |
250 | // Upgrade from V204 to V205 | |
251 | // | |
252 | ||
253 | static BOOL H_UpgradeFromV204(int currVersion, int newVersion) | |
254 | { | |
255 | if (!CreateTable(_T("CREATE TABLE usm_credentials (") | |
256 | _T("id integer not null,") | |
257 | _T("user_name varchar(255) not null,") | |
258 | _T("auth_method integer not null,") | |
259 | _T("priv_method integer not null,") | |
260 | _T("auth_password varchar(255),") | |
261 | _T("priv_password varchar(255),") | |
262 | _T("PRIMARY KEY(id))"))) | |
263 | if (!g_bIgnoreErrors) | |
264 | return FALSE; | |
265 | ||
266 | if (!SQLQuery(_T("UPDATE metadata SET var_value='205' WHERE var_name='SchemaVersion'"))) | |
267 | if (!g_bIgnoreErrors) | |
268 | return FALSE; | |
269 | ||
270 | return TRUE; | |
271 | } | |
272 | ||
273 | ||
e2babedf VK |
274 | // |
275 | // Upgrade from V203 to V204 | |
276 | // | |
277 | ||
278 | static BOOL H_UpgradeFromV203(int currVersion, int newVersion) | |
279 | { | |
280 | static TCHAR batch[] = | |
281 | _T("ALTER TABLE object_properties ADD location_type integer\n") | |
282 | _T("ALTER TABLE object_properties ADD latitude varchar(20)\n") | |
283 | _T("ALTER TABLE object_properties ADD longitude varchar(20)\n") | |
284 | _T("UPDATE object_properties SET location_type=0\n") | |
285 | _T("ALTER TABLE object_properties DROP COLUMN image_id\n") | |
286 | _T("<END>"); | |
287 | ||
288 | if (!SQLBatch(batch)) | |
289 | if (!g_bIgnoreErrors) | |
290 | return FALSE; | |
291 | ||
292 | if (!CreateConfigParam(_T("ConnectionPoolBaseSize"), _T("5"), 1, 1)) | |
293 | if (!g_bIgnoreErrors) | |
294 | return FALSE; | |
295 | ||
296 | if (!CreateConfigParam(_T("ConnectionPoolMaxSize"), _T("20"), 1, 1)) | |
297 | if (!g_bIgnoreErrors) | |
298 | return FALSE; | |
299 | ||
300 | if (!CreateConfigParam(_T("ConnectionPoolCooldownTime"), _T("300"), 1, 1)) | |
301 | if (!g_bIgnoreErrors) | |
302 | return FALSE; | |
303 | ||
a4743a0f VK |
304 | if (g_iSyntax == DB_SYNTAX_ORACLE) |
305 | { | |
306 | if (!SQLQuery(_T("ALTER TABLE object_properties MODIFY comments null\n"))) | |
307 | if (!g_bIgnoreErrors) | |
308 | return FALSE; | |
309 | } | |
310 | ||
e2babedf VK |
311 | if (!ConvertStrings("object_properties", "object_id", "comments")) |
312 | if (!g_bIgnoreErrors) | |
313 | return FALSE; | |
314 | ||
315 | if (!SQLQuery(_T("UPDATE metadata SET var_value='204' WHERE var_name='SchemaVersion'"))) | |
316 | if (!g_bIgnoreErrors) | |
317 | return FALSE; | |
318 | ||
319 | return TRUE; | |
320 | } | |
321 | ||
322 | ||
7cda0d53 VK |
323 | // |
324 | // Upgrade from V202 to V203 | |
325 | // | |
326 | ||
327 | static BOOL H_UpgradeFromV202(int currVersion, int newVersion) | |
328 | { | |
329 | static TCHAR batch[] = | |
330 | _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text)") | |
331 | _T(" VALUES (20,'&Info->Topology table (LLDP)',2,'Topology Table',1,' ','Show topology table (LLDP)','#00')\n") | |
332 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)") | |
333 | _T(" VALUES (20,0,'Chassis ID','.1.0.8802.1.1.2.1.4.1.1.5',0,0)\n") | |
334 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)") | |
335 | _T(" VALUES (20,1,'Local port','.1.0.8802.1.1.2.1.4.1.1.2',5,0)\n") | |
336 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)") | |
337 | _T(" VALUES (20,2,'System name','.1.0.8802.1.1.2.1.4.1.1.9',0,0)\n") | |
338 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)") | |
339 | _T(" VALUES (20,3,'System description','.1.0.8802.1.1.2.1.4.1.1.10',0,0)\n") | |
340 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)") | |
341 | _T(" VALUES (20,4,'Remote port ID','.1.0.8802.1.1.2.1.4.1.1.7',4,0)\n") | |
342 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)") | |
343 | _T(" VALUES (20,5,'Remote port description','.1.0.8802.1.1.2.1.4.1.1.8',0,0)\n") | |
344 | _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (20,-2147483648)\n") | |
345 | _T("<END>"); | |
346 | ||
347 | if (!SQLBatch(batch)) | |
348 | if (!g_bIgnoreErrors) | |
349 | return FALSE; | |
350 | ||
351 | if (!SQLQuery(_T("UPDATE metadata SET var_value='203' WHERE var_name='SchemaVersion'"))) | |
352 | if (!g_bIgnoreErrors) | |
353 | return FALSE; | |
354 | ||
355 | return TRUE; | |
356 | } | |
357 | ||
358 | ||
643c9dcb VK |
359 | // |
360 | // Upgrade from V201 to V202 | |
361 | // | |
362 | ||
363 | static BOOL H_UpgradeFromV201(int currVersion, int newVersion) | |
364 | { | |
a4743a0f VK |
365 | if (g_iSyntax == DB_SYNTAX_ORACLE) |
366 | { | |
367 | static TCHAR oraBatch[] = | |
368 | _T("ALTER TABLE alarms MODIFY message null\n") | |
369 | _T("ALTER TABLE alarms MODIFY alarm_key null\n") | |
370 | _T("ALTER TABLE alarms MODIFY hd_ref null\n") | |
371 | _T("<END>"); | |
372 | ||
373 | if (!SQLBatch(oraBatch)) | |
374 | if (!g_bIgnoreErrors) | |
375 | return FALSE; | |
376 | } | |
377 | ||
643c9dcb VK |
378 | if (!ConvertStrings("alarms", "alarm_id", "message")) |
379 | if (!g_bIgnoreErrors) | |
380 | return FALSE; | |
381 | if (!ConvertStrings("alarms", "alarm_id", "alarm_key")) | |
382 | if (!g_bIgnoreErrors) | |
383 | return FALSE; | |
384 | if (!ConvertStrings("alarms", "alarm_id", "hd_ref")) | |
385 | if (!g_bIgnoreErrors) | |
386 | return FALSE; | |
387 | ||
388 | if (!SQLQuery(_T("UPDATE metadata SET var_value='202' WHERE var_name='SchemaVersion'"))) | |
389 | if (!g_bIgnoreErrors) | |
390 | return FALSE; | |
391 | ||
392 | return TRUE; | |
393 | } | |
394 | ||
395 | ||
31cc1924 VK |
396 | // |
397 | // Upgrade from V200 to V201 | |
398 | // | |
399 | ||
400 | static BOOL H_UpgradeFromV200(int currVersion, int newVersion) | |
401 | { | |
402 | static TCHAR batch[] = | |
403 | _T("ALTER TABLE nodes ADD usm_auth_password varchar(127)\n") | |
404 | _T("ALTER TABLE nodes ADD usm_priv_password varchar(127)\n") | |
405 | _T("ALTER TABLE nodes ADD usm_methods integer\n") | |
e8daf6d5 | 406 | _T("UPDATE nodes SET usm_auth_password='#00',usm_priv_password='#00',usm_methods=0\n") |
31cc1924 VK |
407 | _T("<END>"); |
408 | ||
409 | if (!SQLBatch(batch)) | |
410 | if (!g_bIgnoreErrors) | |
411 | return FALSE; | |
412 | ||
413 | if (!SQLQuery(_T("UPDATE metadata SET var_value='201' WHERE var_name='SchemaVersion'"))) | |
414 | if (!g_bIgnoreErrors) | |
415 | return FALSE; | |
416 | ||
417 | return TRUE; | |
418 | } | |
419 | ||
420 | ||
45d84f8a VK |
421 | // |
422 | // Upgrade from V92 to V200 | |
31cc1924 | 423 | // or from V93 to V201 |
e2babedf VK |
424 | // or from V94 to V202 |
425 | // or from V95 to V203 | |
ce7565e7 VK |
426 | // or from V96 to V204 |
427 | // or from V97 to V205 | |
428 | // or from V98 to V206 | |
45d84f8a VK |
429 | // |
430 | ||
e2babedf | 431 | static BOOL H_UpgradeFromV9x(int currVersion, int newVersion) |
45d84f8a VK |
432 | { |
433 | if (!CreateTable(_T("CREATE TABLE ap_common (") | |
434 | _T("id integer not null,") | |
435 | _T("policy_type integer not null,") | |
436 | _T("version integer not null,") | |
437 | _T("description $SQL:TEXT not null,") | |
438 | _T("PRIMARY KEY(id))"))) | |
439 | if (!g_bIgnoreErrors) | |
440 | return FALSE; | |
441 | ||
442 | if (!CreateTable(_T("CREATE TABLE ap_bindings (") | |
443 | _T("policy_id integer not null,") | |
444 | _T("node_id integer not null,") | |
445 | _T("PRIMARY KEY(policy_id,node_id))"))) | |
446 | if (!g_bIgnoreErrors) | |
447 | return FALSE; | |
448 | ||
449 | if (!CreateTable(_T("CREATE TABLE ap_config_files (") | |
450 | _T("policy_id integer not null,") | |
451 | _T("file_name varchar(63) not null,") | |
452 | _T("file_content $SQL:TEXT not null,") | |
453 | _T("PRIMARY KEY(policy_id))"))) | |
454 | if (!g_bIgnoreErrors) | |
455 | return FALSE; | |
456 | ||
31cc1924 VK |
457 | TCHAR query[256]; |
458 | _sntprintf(query, 256, _T("UPDATE metadata SET var_value='%d' WHERE var_name='SchemaVersion'"), newVersion); | |
459 | if (!SQLQuery(query)) | |
45d84f8a VK |
460 | if (!g_bIgnoreErrors) |
461 | return FALSE; | |
462 | ||
463 | return TRUE; | |
464 | } | |
465 | ||
466 | ||
6e53f004 VK |
467 | // |
468 | // Upgrade from V91 to V92 | |
469 | // | |
470 | ||
31cc1924 | 471 | static BOOL H_UpgradeFromV91(int currVersion, int newVersion) |
6e53f004 VK |
472 | { |
473 | static TCHAR batch[] = | |
474 | _T("DROP TABLE images\n") | |
475 | _T("DROP TABLE default_images\n") | |
476 | _T("<END>"); | |
477 | ||
478 | if (!SQLBatch(batch)) | |
479 | if (!g_bIgnoreErrors) | |
480 | return FALSE; | |
481 | ||
482 | if (!SQLQuery(_T("UPDATE metadata SET var_value='92' WHERE var_name='SchemaVersion'"))) | |
483 | if (!g_bIgnoreErrors) | |
484 | return FALSE; | |
485 | ||
486 | return TRUE; | |
487 | } | |
488 | ||
489 | ||
c45e0213 VK |
490 | // |
491 | // Upgrade from V90 to V91 | |
492 | // | |
493 | ||
31cc1924 | 494 | static BOOL H_UpgradeFromV90(int currVersion, int newVersion) |
c45e0213 VK |
495 | { |
496 | if (!CreateTable(_T("CREATE TABLE userdb_custom_attributes (") | |
497 | _T("object_id integer not null,") | |
498 | _T("attr_name varchar(255) not null,") | |
499 | _T("attr_value $SQL:TEXT not null,") | |
500 | _T("PRIMARY KEY(object_id,attr_name))"))) | |
501 | if (!g_bIgnoreErrors) | |
502 | return FALSE; | |
503 | ||
504 | if (!SQLQuery(_T("UPDATE metadata SET var_value='91' WHERE var_name='SchemaVersion'"))) | |
505 | if (!g_bIgnoreErrors) | |
506 | return FALSE; | |
507 | ||
508 | return TRUE; | |
509 | } | |
510 | ||
511 | ||
4262c0dc VK |
512 | // |
513 | // Upgrade from V89 to V90 | |
514 | // | |
515 | ||
31cc1924 | 516 | static BOOL H_UpgradeFromV89(int currVersion, int newVersion) |
4262c0dc VK |
517 | { |
518 | static TCHAR m_szBatch[] = | |
519 | _T("ALTER TABLE items ADD base_units integer\n") | |
520 | _T("ALTER TABLE items ADD unit_multiplier integer\n") | |
521 | _T("ALTER TABLE items ADD custom_units_name varchar(63)\n") | |
522 | _T("ALTER TABLE items ADD perftab_settings $SQL:TEXT\n") | |
523 | _T("UPDATE items SET base_units=0,unit_multiplier=1,custom_units_name='#00',perftab_settings='#00'\n") | |
524 | _T("<END>"); | |
525 | ||
526 | if (!SQLBatch(m_szBatch)) | |
527 | if (!g_bIgnoreErrors) | |
528 | return FALSE; | |
529 | ||
530 | if (!SQLQuery(_T("UPDATE metadata SET var_value='90' WHERE var_name='SchemaVersion'"))) | |
531 | if (!g_bIgnoreErrors) | |
532 | return FALSE; | |
533 | ||
534 | return TRUE; | |
535 | } | |
536 | ||
537 | ||
538 | // | |
539 | // Upgrade from V88 to V89 | |
540 | // | |
541 | ||
31cc1924 | 542 | static BOOL H_UpgradeFromV88(int currVersion, int newVersion) |
4262c0dc VK |
543 | { |
544 | static TCHAR m_szBatch[] = | |
545 | _T("ALTER TABLE containers ADD enable_auto_bind integer\n") | |
546 | _T("ALTER TABLE containers ADD auto_bind_filter $SQL:TEXT\n") | |
547 | _T("UPDATE containers SET enable_auto_bind=0,auto_bind_filter='#00'\n") | |
548 | _T("ALTER TABLE cluster_resources ADD current_owner integer\n") | |
549 | _T("UPDATE cluster_resources SET current_owner=0\n") | |
550 | _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (") | |
551 | _T("52,'SYS_DB_QUERY_FAILED',4,1,'Database query failed (Query: %1; Error: %2)',") | |
552 | _T("'Generated when SQL query to backend database failed.#0D#0A") | |
553 | _T("Parameters:#0D#0A 1) Query#0D#0A 2) Error message')\n") | |
554 | _T("<END>"); | |
555 | ||
556 | if (!SQLBatch(m_szBatch)) | |
557 | if (!g_bIgnoreErrors) | |
558 | return FALSE; | |
559 | ||
560 | if (!SQLQuery(_T("UPDATE metadata SET var_value='89' WHERE var_name='SchemaVersion'"))) | |
561 | if (!g_bIgnoreErrors) | |
562 | return FALSE; | |
563 | ||
564 | return TRUE; | |
565 | } | |
566 | ||
567 | ||
568 | // | |
569 | // Upgrade from V87 to V88 | |
570 | // | |
571 | ||
31cc1924 | 572 | static BOOL H_UpgradeFromV87(int currVersion, int newVersion) |
4262c0dc VK |
573 | { |
574 | static TCHAR m_szBatch[] = | |
575 | _T("ALTER TABLE templates ADD enable_auto_apply integer\n") | |
576 | _T("ALTER TABLE templates ADD apply_filter $SQL:TEXT\n") | |
577 | _T("UPDATE templates SET enable_auto_apply=0,apply_filter='#00'\n") | |
578 | _T("<END>"); | |
579 | ||
580 | if (!SQLBatch(m_szBatch)) | |
581 | if (!g_bIgnoreErrors) | |
582 | return FALSE; | |
583 | ||
584 | if (!SQLQuery(_T("UPDATE metadata SET var_value='88' WHERE var_name='SchemaVersion'"))) | |
585 | if (!g_bIgnoreErrors) | |
586 | return FALSE; | |
587 | ||
588 | return TRUE; | |
589 | } | |
590 | ||
591 | ||
28f5b9a4 VK |
592 | // |
593 | // Upgrade from V86 to V87 | |
594 | // | |
595 | ||
596 | static BOOL MoveConfigToMetadata(const TCHAR *cfgVar, const TCHAR *mdVar) | |
597 | { | |
598 | TCHAR query[1024], buffer[256]; | |
599 | DB_RESULT hResult; | |
600 | BOOL success; | |
601 | ||
602 | _sntprintf(query, 1024, _T("SELECT var_value FROM config WHERE var_name='%s'"), cfgVar); | |
603 | hResult = SQLSelect(query); | |
604 | if (hResult != NULL) | |
605 | { | |
606 | if (DBGetNumRows(hResult) > 0) | |
607 | { | |
608 | DBGetField(hResult, 0, 0, buffer, 256); | |
609 | DecodeSQLString(buffer); | |
610 | _sntprintf(query, 1024, _T("INSERT INTO metadata (var_name,var_value) VALUES ('%s','%s')"), | |
611 | mdVar, buffer); | |
612 | DBFreeResult(hResult); | |
613 | success = SQLQuery(query); | |
614 | if (success) | |
615 | { | |
616 | _sntprintf(query, 1024, _T("DELETE FROM config WHERE var_name='%s'"), cfgVar); | |
617 | success = SQLQuery(query); | |
618 | } | |
619 | } | |
620 | else | |
621 | { | |
622 | success = TRUE; // Variable missing in 'config' table, nothing to move | |
623 | } | |
624 | } | |
625 | else | |
626 | { | |
627 | success = FALSE; | |
628 | } | |
629 | return success; | |
630 | } | |
631 | ||
31cc1924 | 632 | static BOOL H_UpgradeFromV86(int currVersion, int newVersion) |
28f5b9a4 VK |
633 | { |
634 | if (!CreateTable(_T("CREATE TABLE metadata (") | |
635 | _T("var_name varchar(63) not null,") | |
636 | _T("var_value varchar(255) not null,") | |
637 | _T("PRIMARY KEY(var_name))"))) | |
638 | if (!g_bIgnoreErrors) | |
639 | return FALSE; | |
640 | ||
641 | if (!MoveConfigToMetadata(_T("DBFormatVersion"), _T("SchemaVersion"))) | |
642 | if (!g_bIgnoreErrors) | |
643 | return FALSE; | |
644 | ||
645 | if (!MoveConfigToMetadata(_T("DBSyntax"), _T("Syntax"))) | |
646 | if (!g_bIgnoreErrors) | |
647 | return FALSE; | |
648 | ||
649 | if (!MoveConfigToMetadata(_T("IDataTableCreationCommand"), _T("IDataTableCreationCommand"))) | |
650 | if (!g_bIgnoreErrors) | |
651 | return FALSE; | |
652 | ||
653 | if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_0"), _T("IDataIndexCreationCommand_0"))) | |
654 | if (!g_bIgnoreErrors) | |
655 | return FALSE; | |
656 | ||
657 | if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_1"), _T("IDataIndexCreationCommand_1"))) | |
658 | if (!g_bIgnoreErrors) | |
659 | return FALSE; | |
660 | ||
661 | if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_2"), _T("IDataIndexCreationCommand_2"))) | |
662 | if (!g_bIgnoreErrors) | |
663 | return FALSE; | |
664 | ||
665 | if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_3"), _T("IDataIndexCreationCommand_3"))) | |
666 | if (!g_bIgnoreErrors) | |
667 | return FALSE; | |
668 | ||
669 | if (!SQLQuery(_T("UPDATE metadata SET var_value='87' WHERE var_name='SchemaVersion'"))) | |
670 | if (!g_bIgnoreErrors) | |
671 | return FALSE; | |
672 | ||
673 | return TRUE; | |
674 | } | |
675 | ||
676 | ||
4c4c9b03 VK |
677 | // |
678 | // Upgrade from V85 to V86 | |
679 | // | |
680 | ||
31cc1924 | 681 | static BOOL H_UpgradeFromV85(int currVersion, int newVersion) |
4c4c9b03 VK |
682 | { |
683 | static TCHAR m_szBatch[] = | |
684 | _T("DROP TABLE alarm_grops\n") | |
685 | _T("DROP TABLE alarm_group_map\n") | |
47912c44 VK |
686 | _T("DROP TABLE alarm_change_log\n") |
687 | _T("DROP TABLE lpp\n") | |
688 | _T("DROP TABLE lpp_associations\n") | |
689 | _T("DROP TABLE lpp_rulesets\n") | |
690 | _T("DROP TABLE lpp_rules\n") | |
691 | _T("DROP TABLE lpp_groups\n") | |
4c4c9b03 VK |
692 | _T("<END>"); |
693 | ||
694 | if (!SQLBatch(m_szBatch)) | |
695 | if (!g_bIgnoreErrors) | |
696 | return FALSE; | |
697 | ||
698 | if (!SQLQuery(_T("UPDATE config SET var_value='86' WHERE var_name='DBFormatVersion'"))) | |
699 | if (!g_bIgnoreErrors) | |
700 | return FALSE; | |
701 | ||
702 | return TRUE; | |
703 | } | |
704 | ||
705 | ||
5039dede AK |
706 | // |
707 | // Upgrade from V84 to V85 | |
708 | // | |
709 | ||
31cc1924 | 710 | static BOOL H_UpgradeFromV84(int currVersion, int newVersion) |
5039dede AK |
711 | { |
712 | static TCHAR m_szBatch[] = | |
713 | _T("ALTER TABLE nodes ADD use_ifxtable integer\n") | |
714 | _T("UPDATE nodes SET use_ifxtable=0\n") | |
715 | _T("<END>"); | |
716 | ||
717 | if (!SQLBatch(m_szBatch)) | |
718 | if (!g_bIgnoreErrors) | |
719 | return FALSE; | |
720 | ||
721 | if (!CreateConfigParam(_T("UseIfXTable"), _T("1"), 1, 0)) | |
722 | if (!g_bIgnoreErrors) | |
723 | return FALSE; | |
724 | ||
725 | if (!CreateConfigParam(_T("SMTPRetryCount"), _T("1"), 1, 0)) | |
726 | if (!g_bIgnoreErrors) | |
727 | return FALSE; | |
728 | ||
729 | if (!SQLQuery(_T("UPDATE config SET var_value='85' WHERE var_name='DBFormatVersion'"))) | |
730 | if (!g_bIgnoreErrors) | |
731 | return FALSE; | |
732 | ||
733 | return TRUE; | |
734 | } | |
735 | ||
736 | ||
737 | // | |
738 | // Upgrade from V83 to V84 | |
739 | // | |
740 | ||
31cc1924 | 741 | static BOOL H_UpgradeFromV83(int currVersion, int newVersion) |
5039dede AK |
742 | { |
743 | if (!CreateConfigParam(_T("EnableAgentRegistration"), _T("1"), 1, 0)) | |
744 | if (!g_bIgnoreErrors) | |
745 | return FALSE; | |
746 | ||
747 | if (!CreateConfigParam(_T("AnonymousFileAccess"), _T("0"), 1, 0)) | |
748 | if (!g_bIgnoreErrors) | |
749 | return FALSE; | |
750 | ||
751 | if (!CreateConfigParam(_T("EnableISCListener"), _T("0"), 1, 1)) | |
752 | if (!g_bIgnoreErrors) | |
753 | return FALSE; | |
754 | ||
755 | if (!CreateConfigParam(_T("ReceiveForwardedEvents"), _T("0"), 1, 0)) | |
756 | if (!g_bIgnoreErrors) | |
757 | return FALSE; | |
758 | ||
759 | if (!SQLQuery(_T("UPDATE config SET var_value='84' WHERE var_name='DBFormatVersion'"))) | |
760 | if (!g_bIgnoreErrors) | |
761 | return FALSE; | |
762 | ||
763 | return TRUE; | |
764 | } | |
765 | ||
766 | ||
767 | // | |
768 | // Upgrade from V82 to V83 | |
769 | // | |
770 | ||
31cc1924 | 771 | static BOOL H_UpgradeFromV82(int currVersion, int newVersion) |
5039dede AK |
772 | { |
773 | // Fix incorrect alarm timeouts | |
774 | if (!SQLQuery(_T("UPDATE alarms SET timeout=0,timeout_event=43"))) | |
775 | if (!g_bIgnoreErrors) | |
776 | return FALSE; | |
777 | ||
778 | if (!SQLQuery(_T("UPDATE config SET var_value='83' WHERE var_name='DBFormatVersion'"))) | |
779 | if (!g_bIgnoreErrors) | |
780 | return FALSE; | |
781 | ||
782 | return TRUE; | |
783 | } | |
784 | ||
785 | ||
786 | // | |
787 | // Upgrade from V81 to V82 | |
788 | // | |
789 | ||
31cc1924 | 790 | static BOOL H_UpgradeFromV81(int currVersion, int newVersion) |
5039dede AK |
791 | { |
792 | if (!CreateTable(_T("CREATE TABLE config_clob (") | |
793 | _T("var_name varchar(63) not null,") | |
794 | _T("var_value $SQL:TEXT not null,") | |
795 | _T("PRIMARY KEY(var_name))"))) | |
796 | if (!g_bIgnoreErrors) | |
797 | return FALSE; | |
798 | ||
799 | if (!SQLQuery(_T("UPDATE config SET var_value='82' WHERE var_name='DBFormatVersion'"))) | |
800 | if (!g_bIgnoreErrors) | |
801 | return FALSE; | |
802 | ||
803 | return TRUE; | |
804 | } | |
805 | ||
806 | ||
807 | // | |
808 | // Upgrade from V80 to V81 | |
809 | // | |
810 | ||
31cc1924 | 811 | static BOOL H_UpgradeFromV80(int currVersion, int newVersion) |
5039dede AK |
812 | { |
813 | DB_RESULT hResult; | |
814 | TCHAR query[1024], buffer[1024]; | |
815 | int i; | |
816 | ||
817 | // Update dci_schedules table | |
818 | hResult = SQLSelect(_T("SELECT item_id,schedule FROM dci_schedules")); | |
819 | if (hResult != NULL) | |
820 | { | |
821 | if (!SQLQuery(_T("DROP TABLE dci_schedules"))) | |
822 | if (!g_bIgnoreErrors) | |
823 | return FALSE; | |
824 | ||
825 | if (!CreateTable(_T("CREATE TABLE dci_schedules (") | |
826 | _T("schedule_id integer not null,") | |
827 | _T("item_id integer not null,") | |
828 | _T("schedule varchar(255) not null,") | |
829 | _T("PRIMARY KEY(item_id,schedule_id))"))) | |
830 | if (!g_bIgnoreErrors) | |
831 | return FALSE; | |
832 | ||
833 | for(i = 0; i < DBGetNumRows(hResult); i++) | |
834 | { | |
835 | _sntprintf(query, 1024, _T("INSERT INTO dci_schedules (item_id,schedule_id,schedule) VALUES(%d,%d,'%s')"), | |
836 | DBGetFieldULong(hResult, i, 0), i + 1, DBGetField(hResult, i, 1, buffer, 1024)); | |
837 | if (!SQLQuery(query)) | |
838 | if (!g_bIgnoreErrors) | |
839 | return FALSE; | |
840 | } | |
841 | DBFreeResult(hResult); | |
842 | } | |
843 | else | |
844 | { | |
845 | if (!g_bIgnoreErrors) | |
846 | return FALSE; | |
847 | } | |
848 | ||
849 | // Update address_lists table | |
850 | hResult = SQLSelect(_T("SELECT list_type,community_id,addr_type,addr1,addr2 FROM address_lists")); | |
851 | if (hResult != NULL) | |
852 | { | |
853 | if (!SQLQuery(_T("DROP TABLE address_lists"))) | |
854 | if (!g_bIgnoreErrors) | |
855 | return FALSE; | |
856 | ||
857 | if (!CreateTable(_T("CREATE TABLE address_lists (") | |
858 | _T("list_type integer not null,") | |
859 | _T("community_id integer not null,") | |
860 | _T("addr_type integer not null,") | |
861 | _T("addr1 varchar(15) not null,") | |
862 | _T("addr2 varchar(15) not null,") | |
863 | _T("PRIMARY KEY(list_type,community_id,addr_type,addr1,addr2))"))) | |
864 | if (!g_bIgnoreErrors) | |
865 | return FALSE; | |
866 | ||
867 | for(i = 0; i < DBGetNumRows(hResult); i++) | |
868 | { | |
869 | _sntprintf(query, 1024, _T("INSERT INTO address_lists (list_type,community_id,addr_type,addr1,addr2) VALUES(%d,%d,%d,'%s','%s')"), | |
870 | DBGetFieldULong(hResult, i, 0), DBGetFieldULong(hResult, i, 1), | |
871 | DBGetFieldULong(hResult, i, 2), DBGetField(hResult, i, 3, buffer, 64), | |
872 | DBGetField(hResult, i, 4, &buffer[128], 64)); | |
873 | if (!SQLQuery(query)) | |
874 | if (!g_bIgnoreErrors) | |
875 | return FALSE; | |
876 | } | |
877 | ||
878 | DBFreeResult(hResult); | |
879 | } | |
880 | else | |
881 | { | |
882 | if (!g_bIgnoreErrors) | |
883 | return FALSE; | |
884 | } | |
885 | ||
886 | // Create new tables | |
887 | if (!CreateTable(_T("CREATE TABLE object_custom_attributes (") | |
888 | _T("object_id integer not null,") | |
889 | _T("attr_name varchar(127) not null,") | |
890 | _T("attr_value $SQL:TEXT not null,") | |
891 | _T("PRIMARY KEY(object_id,attr_name))"))) | |
892 | if (!g_bIgnoreErrors) | |
893 | return FALSE; | |
894 | ||
895 | if (!CreateTable(_T("CREATE TABLE web_maps (") | |
896 | _T("id integer not null,") | |
897 | _T("title varchar(63) not null,") | |
898 | _T("properties $SQL:TEXT not null,") | |
899 | _T("data $SQL:TEXT not null,") | |
900 | _T("PRIMARY KEY(id))"))) | |
901 | if (!g_bIgnoreErrors) | |
902 | return FALSE; | |
903 | ||
904 | if (!SQLQuery(_T("UPDATE config SET var_value='81' WHERE var_name='DBFormatVersion'"))) | |
905 | if (!g_bIgnoreErrors) | |
906 | return FALSE; | |
907 | ||
908 | return TRUE; | |
909 | } | |
910 | ||
911 | ||
912 | // | |
913 | // Upgrade from V79 to V80 | |
914 | // | |
915 | ||
31cc1924 | 916 | static BOOL H_UpgradeFromV79(int currVersion, int newVersion) |
5039dede AK |
917 | { |
918 | static TCHAR m_szBatch[] = | |
919 | _T("ALTER TABLE nodes ADD uname varchar(255)\n") | |
920 | _T("UPDATE nodes SET uname='#00'\n") | |
921 | _T("<END>"); | |
922 | ||
923 | if (!SQLBatch(m_szBatch)) | |
924 | if (!g_bIgnoreErrors) | |
925 | return FALSE; | |
926 | ||
927 | if (!SQLQuery(_T("UPDATE config SET var_value='80' WHERE var_name='DBFormatVersion'"))) | |
928 | if (!g_bIgnoreErrors) | |
929 | return FALSE; | |
930 | ||
931 | return TRUE; | |
932 | } | |
933 | ||
934 | ||
935 | // | |
936 | // Upgrade from V78 to V79 | |
937 | // | |
938 | ||
31cc1924 | 939 | static BOOL H_UpgradeFromV78(int currVersion, int newVersion) |
5039dede AK |
940 | { |
941 | static TCHAR m_szBatch[] = | |
942 | _T("DELETE FROM config WHERE var_name='RetainCustomInterfaceNames'\n") | |
943 | _T("DROP TABLE modules\n") | |
944 | _T("<END>"); | |
945 | static TCHAR m_szMySQLBatch[] = | |
946 | _T("ALTER TABLE users MODIFY COLUMN cert_mapping_data text not null\n") | |
947 | _T("ALTER TABLE user_profiles MODIFY COLUMN var_value text not null\n") | |
948 | _T("ALTER TABLE object_properties MODIFY COLUMN comments text not null\n") | |
949 | _T("ALTER TABLE network_services MODIFY COLUMN check_request text not null\n") | |
950 | _T("ALTER TABLE network_services MODIFY COLUMN check_responce text not null\n") | |
951 | _T("ALTER TABLE conditions MODIFY COLUMN script text not null\n") | |
952 | _T("ALTER TABLE container_categories MODIFY COLUMN description text not null\n") | |
953 | _T("ALTER TABLE items MODIFY COLUMN transformation text not null\n") | |
954 | _T("ALTER TABLE event_cfg MODIFY COLUMN description text not null\n") | |
955 | _T("ALTER TABLE actions MODIFY COLUMN action_data text not null\n") | |
956 | _T("ALTER TABLE event_policy MODIFY COLUMN comments text not null\n") | |
957 | _T("ALTER TABLE event_policy MODIFY COLUMN script text not null\n") | |
958 | _T("ALTER TABLE alarm_change_log MODIFY COLUMN info_text text not null\n") | |
959 | _T("ALTER TABLE alarm_notes MODIFY COLUMN note_text text not null\n") | |
960 | _T("ALTER TABLE object_tools MODIFY COLUMN tool_data text not null\n") | |
961 | _T("ALTER TABLE syslog MODIFY COLUMN msg_text text not null\n") | |
962 | _T("ALTER TABLE script_library MODIFY COLUMN script_code text not null\n") | |
963 | _T("ALTER TABLE snmp_trap_log MODIFY COLUMN trap_varlist text not null\n") | |
964 | _T("ALTER TABLE maps MODIFY COLUMN description text not null\n") | |
965 | _T("ALTER TABLE agent_configs MODIFY COLUMN config_file text not null\n") | |
966 | _T("ALTER TABLE agent_configs MODIFY COLUMN config_filter text not null\n") | |
967 | _T("ALTER TABLE graphs MODIFY COLUMN config text not null\n") | |
968 | _T("ALTER TABLE certificates MODIFY COLUMN cert_data text not null\n") | |
969 | _T("ALTER TABLE certificates MODIFY COLUMN subject text not null\n") | |
970 | _T("ALTER TABLE certificates MODIFY COLUMN comments text not null\n") | |
971 | _T("ALTER TABLE audit_log MODIFY COLUMN message text not null\n") | |
972 | _T("ALTER TABLE situations MODIFY COLUMN comments text not null\n") | |
973 | _T("<END>"); | |
974 | ||
975 | if (!SQLBatch(m_szBatch)) | |
976 | if (!g_bIgnoreErrors) | |
977 | return FALSE; | |
978 | ||
979 | if (g_iSyntax == DB_SYNTAX_MYSQL) | |
980 | { | |
981 | if (!SQLBatch(m_szMySQLBatch)) | |
982 | if (!g_bIgnoreErrors) | |
983 | return FALSE; | |
984 | } | |
985 | ||
986 | if (!SQLQuery(_T("UPDATE config SET var_value='79' WHERE var_name='DBFormatVersion'"))) | |
987 | if (!g_bIgnoreErrors) | |
988 | return FALSE; | |
989 | ||
990 | return TRUE; | |
991 | } | |
992 | ||
993 | ||
994 | // | |
995 | // Upgrade from V77 to V78 | |
996 | // | |
997 | ||
31cc1924 | 998 | static BOOL H_UpgradeFromV77(int currVersion, int newVersion) |
5039dede AK |
999 | { |
1000 | if (!CreateTable(_T("CREATE TABLE trusted_nodes (") | |
1001 | _T("source_object_id integer not null,") | |
1002 | _T("target_node_id integer not null,") | |
1003 | _T("PRIMARY KEY(source_object_id,target_node_id))"))) | |
1004 | if (!g_bIgnoreErrors) | |
1005 | return FALSE; | |
1006 | ||
1007 | if (!CreateConfigParam(_T("CheckTrustedNodes"), _T("1"), 1, 1)) | |
1008 | if (!g_bIgnoreErrors) | |
1009 | return FALSE; | |
1010 | ||
1011 | if (!SQLQuery(_T("UPDATE config SET var_value='78' WHERE var_name='DBFormatVersion'"))) | |
1012 | if (!g_bIgnoreErrors) | |
1013 | return FALSE; | |
1014 | ||
1015 | return TRUE; | |
1016 | } | |
1017 | ||
1018 | ||
1019 | // | |
1020 | // Upgrade from V76 to V77 | |
1021 | // | |
1022 | ||
31cc1924 | 1023 | static BOOL H_UpgradeFromV76(int currVersion, int newVersion) |
5039dede AK |
1024 | { |
1025 | DB_RESULT hResult; | |
1026 | int i, count, seq; | |
1027 | DWORD id, lastId; | |
1028 | TCHAR query[1024]; | |
1029 | ||
1030 | hResult = SQLSelect(_T("SELECT condition_id,dci_id,node_id,dci_func,num_polls FROM cond_dci_map ORDER BY condition_id")); | |
1031 | if (hResult == NULL) | |
1032 | if (!g_bIgnoreErrors) | |
1033 | return FALSE; | |
1034 | ||
1035 | if (!SQLQuery(_T("DROP TABLE cond_dci_map"))) | |
1036 | if (!g_bIgnoreErrors) | |
1037 | goto error; | |
1038 | ||
1039 | if (!CreateTable(_T("CREATE TABLE cond_dci_map (") | |
1040 | _T("condition_id integer not null,") | |
1041 | _T("sequence_number integer not null,") | |
1042 | _T("dci_id integer not null,") | |
1043 | _T("node_id integer not null,") | |
1044 | _T("dci_func integer not null,") | |
1045 | _T("num_polls integer not null,") | |
1046 | _T("PRIMARY KEY(condition_id,sequence_number))"))) | |
1047 | if (!g_bIgnoreErrors) | |
1048 | goto error; | |
1049 | ||
1050 | count = DBGetNumRows(hResult); | |
1051 | for(i = 0, seq = 0, lastId = 0; i < count; i++, seq++) | |
1052 | { | |
1053 | id = DBGetFieldULong(hResult, i, 0); | |
1054 | if (id != lastId) | |
1055 | { | |
1056 | seq = 0; | |
1057 | lastId = id; | |
1058 | } | |
1059 | _sntprintf(query, 1024, _T("INSERT INTO cond_dci_map (condition_id,sequence_number,dci_id,node_id,dci_func,num_polls) VALUES (%d,%d,%d,%d,%d,%d)"), | |
1060 | id, seq, DBGetFieldULong(hResult, i, 1), DBGetFieldULong(hResult, i, 2), | |
1061 | DBGetFieldULong(hResult, i, 3), DBGetFieldULong(hResult, i, 4)); | |
1062 | if (!SQLQuery(query)) | |
1063 | if (!g_bIgnoreErrors) | |
1064 | goto error; | |
1065 | } | |
1066 | ||
1067 | DBFreeResult(hResult); | |
1068 | ||
1069 | if (!SQLQuery(_T("UPDATE config SET var_value='77' WHERE var_name='DBFormatVersion'"))) | |
1070 | if (!g_bIgnoreErrors) | |
1071 | return FALSE; | |
1072 | ||
1073 | return TRUE; | |
1074 | ||
1075 | error: | |
1076 | DBFreeResult(hResult); | |
1077 | return FALSE; | |
1078 | } | |
1079 | ||
1080 | ||
1081 | // | |
1082 | // Upgrade from V75 to V76 | |
1083 | // | |
1084 | ||
31cc1924 | 1085 | static BOOL H_UpgradeFromV75(int currVersion, int newVersion) |
5039dede AK |
1086 | { |
1087 | static TCHAR m_szBatch[] = | |
1088 | _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (") | |
1089 | _T("50,'SYS_NETWORK_CONN_LOST',4,1,'NetXMS server network connectivity lost',") | |
1090 | _T("'Generated when system detects loss of network connectivity based on beacon ") | |
1091 | _T("probing.#0D#0AParameters:#0D#0A 1) Number of beacons')\n") | |
1092 | _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (") | |
1093 | _T("51,'SYS_NETWORK_CONN_RESTORED',0,1,'NetXMS server network connectivity restored',") | |
1094 | _T("'Generated when system detects restoration of network connectivity based on ") | |
1095 | _T("beacon probing.#0D#0AParameters:#0D#0A 1) Number of beacons')\n") | |
1096 | _T("<END>"); | |
1097 | ||
1098 | if (!SQLBatch(m_szBatch)) | |
1099 | if (!g_bIgnoreErrors) | |
1100 | return FALSE; | |
1101 | ||
1102 | if (!CreateConfigParam(_T("AgentCommandTimeout"), _T("2000"), 1, 1)) | |
1103 | if (!g_bIgnoreErrors) | |
1104 | return FALSE; | |
1105 | ||
1106 | if (!CreateConfigParam(_T("BeaconHosts"), _T(""), 1, 1)) | |
1107 | if (!g_bIgnoreErrors) | |
1108 | return FALSE; | |
1109 | ||
1110 | if (!CreateConfigParam(_T("BeaconTimeout"), _T("1000"), 1, 1)) | |
1111 | if (!g_bIgnoreErrors) | |
1112 | return FALSE; | |
1113 | ||
1114 | if (!CreateConfigParam(_T("BeaconPollingInterval"), _T("1000"), 1, 1)) | |
1115 | if (!g_bIgnoreErrors) | |
1116 | return FALSE; | |
1117 | ||
1118 | if (!SQLQuery(_T("UPDATE config SET var_value='76' WHERE var_name='DBFormatVersion'"))) | |
1119 | if (!g_bIgnoreErrors) | |
1120 | return FALSE; | |
1121 | ||
1122 | return TRUE; | |
1123 | } | |
1124 | ||
1125 | ||
1126 | // | |
1127 | // Upgrade from V74 to V75 | |
1128 | // | |
1129 | ||
31cc1924 | 1130 | static BOOL H_UpgradeFromV74(int currVersion, int newVersion) |
5039dede AK |
1131 | { |
1132 | static TCHAR m_szBatch[] = | |
1133 | _T("ALTER TABLE address_lists ADD community_id integer\n") | |
1134 | _T("UPDATE address_lists SET community_id=0\n") | |
1135 | _T("<END>"); | |
1136 | ||
1137 | if (!SQLBatch(m_szBatch)) | |
1138 | if (!g_bIgnoreErrors) | |
1139 | return FALSE; | |
1140 | ||
1141 | if (!CreateTable(_T("CREATE TABLE snmp_communities (") | |
1142 | _T("id integer not null,") | |
1143 | _T("community varchar(255) not null,") | |
1144 | _T("PRIMARY KEY(id))"))) | |
1145 | if (!g_bIgnoreErrors) | |
1146 | return FALSE; | |
1147 | ||
1148 | if (!CreateConfigParam(_T("UseInterfaceAliases"), _T("0"), 1, 0)) | |
1149 | if (!g_bIgnoreErrors) | |
1150 | return FALSE; | |
1151 | ||
1152 | if (!CreateConfigParam(_T("SyncNodeNamesWithDNS"), _T("0"), 1, 0)) | |
1153 | if (!g_bIgnoreErrors) | |
1154 | return FALSE; | |
1155 | ||
1156 | if (!SQLQuery(_T("UPDATE config SET var_value='75' WHERE var_name='DBFormatVersion'"))) | |
1157 | if (!g_bIgnoreErrors) | |
1158 | return FALSE; | |
1159 | ||
1160 | return TRUE; | |
1161 | } | |
1162 | ||
1163 | ||
1164 | // | |
1165 | // Upgrade from V73 to V74 | |
1166 | // | |
1167 | ||
31cc1924 | 1168 | static BOOL H_UpgradeFromV73(int currVersion, int newVersion) |
5039dede AK |
1169 | { |
1170 | static TCHAR m_szBatch[] = | |
1171 | _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ") | |
1172 | _T("VALUES (48,'SYS_EVENT_STORM_DETECTED',3,1,'Event storm detected (Events per second: %1)',") | |
1173 | _T("'Generated when system detects an event storm.#0D#0AParameters:#0D#0A") | |
1174 | _T(" 1) Events per second#0D#0A 2) Duration#0D#0A 3) Threshold')\n") | |
1175 | _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ") | |
1176 | _T("VALUES (49,'SYS_EVENT_STORM_ENDED',0,1,'Event storm ended',") | |
1177 | _T("'Generated when system clears event storm condition.#0D#0AParameters:#0D#0A") | |
1178 | _T(" 1) Events per second#0D#0A 2) Duration#0D#0A 3) Threshold')\n") | |
1179 | _T("DELETE FROM config WHERE var_name='NumberOfEventProcessors'\n") | |
1180 | _T("DELETE FROM config WHERE var_name='EventStormThreshold'\n") | |
1181 | _T("<END>"); | |
1182 | ||
1183 | if (!SQLBatch(m_szBatch)) | |
1184 | if (!g_bIgnoreErrors) | |
1185 | return FALSE; | |
1186 | ||
1187 | if (!CreateConfigParam(_T("EnableEventStormDetection"), _T("0"), 1, 1)) | |
1188 | if (!g_bIgnoreErrors) | |
1189 | return FALSE; | |
1190 | ||
1191 | if (!CreateConfigParam(_T("EventStormEventsPerSecond"), _T("100"), 1, 1)) | |
1192 | if (!g_bIgnoreErrors) | |
1193 | return FALSE; | |
1194 | ||
1195 | if (!CreateConfigParam(_T("EventStormDuration"), _T("15"), 1, 1)) | |
1196 | if (!g_bIgnoreErrors) | |
1197 | return FALSE; | |
1198 | ||
1199 | if (!SQLQuery(_T("UPDATE config SET var_value='74' WHERE var_name='DBFormatVersion'"))) | |
1200 | if (!g_bIgnoreErrors) | |
1201 | return FALSE; | |
1202 | ||
1203 | return TRUE; | |
1204 | } | |
1205 | ||
1206 | ||
1207 | // | |
1208 | // Upgrade from V72 to V73 | |
1209 | // | |
1210 | ||
31cc1924 | 1211 | static BOOL H_UpgradeFromV72(int currVersion, int newVersion) |
5039dede AK |
1212 | { |
1213 | static TCHAR m_szBatch[] = | |
1214 | _T("ALTER TABLE event_policy ADD situation_id integer\n") | |
1215 | _T("ALTER TABLE event_policy ADD situation_instance varchar(255)\n") | |
1216 | _T("UPDATE event_policy SET situation_id=0,situation_instance='#00'\n") | |
1217 | _T("<END>"); | |
1218 | ||
1219 | if (!SQLBatch(m_szBatch)) | |
1220 | if (!g_bIgnoreErrors) | |
1221 | return FALSE; | |
1222 | ||
1223 | if (!CreateTable(_T("CREATE TABLE policy_situation_attr_list (") | |
1224 | _T("rule_id integer not null,") | |
1225 | _T("situation_id integer not null,") | |
1226 | _T("attr_name varchar(255) not null,") | |
1227 | _T("attr_value varchar(255) not null,") | |
1228 | _T("PRIMARY KEY(rule_id,situation_id,attr_name))"))) | |
1229 | if (!g_bIgnoreErrors) | |
1230 | return FALSE; | |
1231 | ||
1232 | if (!CreateTable(_T("CREATE TABLE situations (") | |
1233 | _T("id integer not null,") | |
1234 | _T("name varchar(127) not null,") | |
1235 | _T("comments $SQL:TEXT not null,") | |
1236 | _T("PRIMARY KEY(id))"))) | |
1237 | if (!g_bIgnoreErrors) | |
1238 | return FALSE; | |
1239 | ||
1240 | if (!CreateConfigParam(_T("RetainCustomInterfaceNames"), _T("0"), 1, 0)) | |
1241 | if (!g_bIgnoreErrors) | |
1242 | return FALSE; | |
1243 | ||
1244 | if (!CreateConfigParam(_T("AllowDirectSMS"), _T("0"), 1, 0)) | |
1245 | if (!g_bIgnoreErrors) | |
1246 | return FALSE; | |
1247 | ||
1248 | if (!CreateConfigParam(_T("EventStormThreshold"), _T("0"), 1, 1)) | |
1249 | if (!g_bIgnoreErrors) | |
1250 | return FALSE; | |
1251 | ||
1252 | if (!SQLQuery(_T("UPDATE config SET var_value='73' WHERE var_name='DBFormatVersion'"))) | |
1253 | if (!g_bIgnoreErrors) | |
1254 | return FALSE; | |
1255 | ||
1256 | return TRUE; | |
1257 | } | |
1258 | ||
1259 | ||
1260 | // | |
1261 | // Upgrade from V71 to V72 | |
1262 | // | |
1263 | ||
31cc1924 | 1264 | static BOOL H_UpgradeFromV71(int currVersion, int newVersion) |
5039dede AK |
1265 | { |
1266 | static TCHAR m_szBatch[] = | |
1267 | _T("ALTER TABLE items ADD proxy_node integer\n") | |
1268 | _T("UPDATE items SET proxy_node=0\n") | |
1269 | _T("<END>"); | |
1270 | ||
1271 | if (!SQLBatch(m_szBatch)) | |
1272 | if (!g_bIgnoreErrors) | |
1273 | return FALSE; | |
1274 | ||
1275 | if (!SQLQuery(_T("UPDATE config SET var_value='72' WHERE var_name='DBFormatVersion'"))) | |
1276 | if (!g_bIgnoreErrors) | |
1277 | return FALSE; | |
1278 | ||
1279 | return TRUE; | |
1280 | } | |
1281 | ||
1282 | ||
1283 | // | |
1284 | // Upgrade from V70 to V71 | |
1285 | // | |
1286 | ||
31cc1924 | 1287 | static BOOL H_UpgradeFromV70(int currVersion, int newVersion) |
5039dede AK |
1288 | { |
1289 | static TCHAR m_szBatch[] = | |
1290 | _T("ALTER TABLE nodes ADD required_polls integer\n") | |
1291 | _T("UPDATE nodes SET required_polls=0\n") | |
1292 | _T("ALTER TABLE interfaces ADD required_polls integer\n") | |
1293 | _T("UPDATE interfaces SET required_polls=0\n") | |
1294 | _T("ALTER TABLE network_services ADD required_polls integer\n") | |
1295 | _T("UPDATE network_services SET required_polls=0\n") | |
1296 | _T("<END>"); | |
1297 | ||
1298 | if (!SQLBatch(m_szBatch)) | |
1299 | if (!g_bIgnoreErrors) | |
1300 | return FALSE; | |
1301 | ||
1302 | if (!CreateConfigParam(_T("PollCountForStatusChange"), _T("1"), 1, 1)) | |
1303 | if (!g_bIgnoreErrors) | |
1304 | return FALSE; | |
1305 | ||
1306 | if (!SQLQuery(_T("UPDATE config SET var_value='71' WHERE var_name='DBFormatVersion'"))) | |
1307 | if (!g_bIgnoreErrors) | |
1308 | return FALSE; | |
1309 | ||
1310 | return TRUE; | |
1311 | } | |
1312 | ||
1313 | ||
1314 | // | |
1315 | // Upgrade from V69 to V70 | |
1316 | // | |
1317 | ||
31cc1924 | 1318 | static BOOL H_UpgradeFromV69(int currVersion, int newVersion) |
5039dede AK |
1319 | { |
1320 | static TCHAR m_szBatch[] = | |
1321 | _T("ALTER TABLE snmp_trap_cfg ADD user_tag varchar(63)\n") | |
1322 | _T("UPDATE snmp_trap_cfg SET user_tag='#00'\n") | |
1323 | _T("ALTER TABLE event_log ADD user_tag varchar(63)\n") | |
1324 | _T("UPDATE event_log SET user_tag='#00'\n") | |
1325 | _T("<END>"); | |
1326 | int n; | |
1327 | TCHAR buffer[64]; | |
1328 | ||
1329 | if (!SQLBatch(m_szBatch)) | |
1330 | if (!g_bIgnoreErrors) | |
1331 | return FALSE; | |
1332 | ||
1333 | // Convert event log retention time from seconds to days | |
1334 | n = ConfigReadInt(_T("EventLogRetentionTime"), 5184000) / 86400; | |
1335 | _stprintf(buffer, _T("%d"), max(n, 1)); | |
1336 | if (!CreateConfigParam(_T("EventLogRetentionTime"), buffer, 1, 0, TRUE)) | |
1337 | if (!g_bIgnoreErrors) | |
1338 | return FALSE; | |
1339 | ||
1340 | // Convert event log retention time from seconds to days | |
1341 | n = ConfigReadInt(_T("SyslogRetentionTime"), 5184000) / 86400; | |
1342 | _stprintf(buffer, _T("%d"), max(n, 1)); | |
1343 | if (!CreateConfigParam(_T("SyslogRetentionTime"), buffer, 1, 0, TRUE)) | |
1344 | if (!g_bIgnoreErrors) | |
1345 | return FALSE; | |
1346 | ||
1347 | if (!SQLQuery(_T("UPDATE config SET var_value='70' WHERE var_name='DBFormatVersion'"))) | |
1348 | if (!g_bIgnoreErrors) | |
1349 | return FALSE; | |
1350 | ||
1351 | return TRUE; | |
1352 | } | |
1353 | ||
1354 | ||
1355 | // | |
1356 | // Upgrade from V68 to V69 | |
1357 | // | |
1358 | ||
31cc1924 | 1359 | static BOOL H_UpgradeFromV68(int currVersion, int newVersion) |
5039dede AK |
1360 | { |
1361 | if (!CreateTable(_T("CREATE TABLE audit_log (") | |
1362 | _T("record_id integer not null,") | |
1363 | _T("timestamp integer not null,") | |
1364 | _T("subsystem varchar(32) not null,") | |
1365 | _T("success integer not null,") | |
1366 | _T("user_id integer not null,") | |
1367 | _T("workstation varchar(63) not null,") | |
1368 | _T("object_id integer not null,") | |
1369 | _T("message $SQL:TEXT not null,") | |
1370 | _T("PRIMARY KEY(record_id))"))) | |
1371 | if (!g_bIgnoreErrors) | |
1372 | return FALSE; | |
1373 | ||
1374 | if (!CreateConfigParam(_T("EnableAuditLog"), _T("1"), 1, 1)) | |
1375 | if (!g_bIgnoreErrors) | |
1376 | return FALSE; | |
1377 | ||
1378 | if (!CreateConfigParam(_T("AuditLogRetentionTime"), _T("90"), 1, 0)) | |
1379 | if (!g_bIgnoreErrors) | |
1380 | return FALSE; | |
1381 | ||
1382 | if (!SQLQuery(_T("UPDATE config SET var_value='69' WHERE var_name='DBFormatVersion'"))) | |
1383 | if (!g_bIgnoreErrors) | |
1384 | return FALSE; | |
1385 | ||
1386 | return TRUE; | |
1387 | } | |
1388 | ||
1389 | ||
1390 | // | |
1391 | // Upgrade from V67 to V68 | |
1392 | // | |
1393 | ||
31cc1924 | 1394 | static BOOL H_UpgradeFromV67(int currVersion, int newVersion) |
5039dede AK |
1395 | { |
1396 | static TCHAR m_szBatch[] = | |
1397 | _T("ALTER TABLE thresholds ADD repeat_interval integer\n") | |
1398 | _T("UPDATE thresholds SET repeat_interval=-1\n") | |
1399 | _T("<END>"); | |
1400 | ||
1401 | if (!SQLBatch(m_szBatch)) | |
1402 | if (!g_bIgnoreErrors) | |
1403 | return FALSE; | |
1404 | ||
1405 | if (!CreateConfigParam(_T("ThresholdRepeatInterval"), _T("0"), 1, 1)) | |
1406 | if (!g_bIgnoreErrors) | |
1407 | return FALSE; | |
1408 | ||
1409 | if (!SQLQuery(_T("UPDATE config SET var_value='68' WHERE var_name='DBFormatVersion'"))) | |
1410 | if (!g_bIgnoreErrors) | |
1411 | return FALSE; | |
1412 | ||
1413 | return TRUE; | |
1414 | } | |
1415 | ||
1416 | ||
1417 | // | |
1418 | // Upgrade from V66 to V67 | |
1419 | // | |
1420 | ||
31cc1924 | 1421 | static BOOL H_UpgradeFromV66(int currVersion, int newVersion) |
5039dede AK |
1422 | { |
1423 | static TCHAR m_szBatch[] = | |
1424 | _T("ALTER TABLE subnets ADD synthetic_mask integer\n") | |
1425 | _T("UPDATE subnets SET synthetic_mask=0\n") | |
1426 | _T("ALTER TABLE interfaces ADD synthetic_mask integer\n") | |
1427 | _T("UPDATE interfaces SET synthetic_mask=0\n") | |
1428 | _T("<END>"); | |
1429 | ||
1430 | if (!SQLBatch(m_szBatch)) | |
1431 | if (!g_bIgnoreErrors) | |
1432 | return FALSE; | |
1433 | ||
1434 | if (!SQLQuery(_T("UPDATE config SET var_value='67' WHERE var_name='DBFormatVersion'"))) | |
1435 | if (!g_bIgnoreErrors) | |
1436 | return FALSE; | |
1437 | ||
1438 | return TRUE; | |
1439 | } | |
1440 | ||
1441 | ||
1442 | // | |
1443 | // Upgrade from V65 to V66 | |
1444 | // | |
1445 | ||
31cc1924 | 1446 | static BOOL H_UpgradeFromV65(int currVersion, int newVersion) |
5039dede AK |
1447 | { |
1448 | static TCHAR m_szBatch[] = | |
1449 | _T("ALTER TABLE submap_links ADD port1 varchar(255)\n") | |
1450 | _T("ALTER TABLE submap_links ADD port2 varchar(255)\n") | |
1451 | _T("UPDATE submap_links SET port1='#00',port2='#00'\n") | |
1452 | _T("<END>"); | |
1453 | ||
1454 | if (!SQLBatch(m_szBatch)) | |
1455 | if (!g_bIgnoreErrors) | |
1456 | return FALSE; | |
1457 | ||
1458 | if (!SQLQuery(_T("UPDATE config SET var_value='66' WHERE var_name='DBFormatVersion'"))) | |
1459 | if (!g_bIgnoreErrors) | |
1460 | return FALSE; | |
1461 | ||
1462 | return TRUE; | |
1463 | } | |
1464 | ||
1465 | ||
1466 | // | |
1467 | // Upgrade from V64 to V65 | |
1468 | // | |
1469 | ||
31cc1924 | 1470 | static BOOL H_UpgradeFromV64(int currVersion, int newVersion) |
5039dede AK |
1471 | { |
1472 | static TCHAR m_szPGSQLBatch[] = | |
1473 | _T("ALTER TABLE nodes ADD new_community varchar(127)\n") | |
1474 | _T("UPDATE nodes SET new_community=community\n") | |
1475 | _T("ALTER TABLE nodes DROP COLUMN community\n") | |
1476 | _T("ALTER TABLE nodes RENAME COLUMN new_community TO community\n") | |
1477 | _T("ALTER TABLE nodes ALTER COLUMN community SET NOT NULL\n") | |
1478 | _T("<END>"); | |
1479 | ||
1480 | switch(g_iSyntax) | |
1481 | { | |
1482 | case DB_SYNTAX_MYSQL: | |
1483 | case DB_SYNTAX_ORACLE: | |
1484 | if (!SQLQuery(_T("ALTER TABLE nodes MODIFY community varchar(127)"))) | |
1485 | if (!g_bIgnoreErrors) | |
1486 | return FALSE; | |
1487 | break; | |
1488 | case DB_SYNTAX_PGSQL: | |
1489 | if (g_bTrace) | |
1490 | ShowQuery(_T("ALTER TABLE nodes ALTER COLUMN community TYPE varchar(127)")); | |
1491 | ||
1492 | if (!DBQuery(g_hCoreDB, _T("ALTER TABLE nodes ALTER COLUMN community TYPE varchar(127)"))) | |
1493 | { | |
1494 | // Assume that we are using PostgreSQL oldest than 8.x | |
1495 | if (!SQLBatch(m_szPGSQLBatch)) | |
1496 | if (!g_bIgnoreErrors) | |
1497 | return FALSE; | |
1498 | } | |
1499 | break; | |
1500 | case DB_SYNTAX_MSSQL: | |
1501 | if (!SQLQuery(_T("ALTER TABLE nodes ALTER COLUMN community varchar(127)"))) | |
1502 | if (!g_bIgnoreErrors) | |
1503 | return FALSE; | |
1504 | break; | |
1505 | case DB_SYNTAX_SQLITE: | |
1506 | _tprintf(_T("WARNING: Due to limitations of SQLite requested operation cannot be completed\nYou system will still be limited to use SNMP commonity strings not longer than 32 characters.\n")); | |
1507 | break; | |
1508 | default: | |
1509 | _tprintf(_T("INTERNAL ERROR: Unknown database syntax %d\n"), g_iSyntax); | |
1510 | break; | |
1511 | } | |
1512 | ||
1513 | if (!SQLQuery(_T("UPDATE config SET var_value='65' WHERE var_name='DBFormatVersion'"))) | |
1514 | if (!g_bIgnoreErrors) | |
1515 | return FALSE; | |
1516 | ||
1517 | return TRUE; | |
1518 | } | |
1519 | ||
1520 | ||
1521 | // | |
1522 | // Upgrade from V63 to V64 | |
1523 | // | |
1524 | ||
31cc1924 | 1525 | static BOOL H_UpgradeFromV63(int currVersion, int newVersion) |
5039dede AK |
1526 | { |
1527 | static TCHAR m_szBatch[] = | |
1528 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (15,'.1.3.6.1.4.1.45.3.29.*',3,0)\n") | |
1529 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (16,'.1.3.6.1.4.1.45.3.41.*',3,0)\n") | |
1530 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (17,'.1.3.6.1.4.1.45.3.45.*',3,0)\n") | |
1531 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (18,'.1.3.6.1.4.1.45.3.43.*',3,0)\n") | |
1532 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (19,'.1.3.6.1.4.1.45.3.57.*',3,0)\n") | |
1533 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (20,'.1.3.6.1.4.1.45.3.49.*',3,0)\n") | |
1534 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (21,'.1.3.6.1.4.1.45.3.54.*',3,0)\n") | |
1535 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (22,'.1.3.6.1.4.1.45.3.63.*',3,0)\n") | |
1536 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (23,'.1.3.6.1.4.1.45.3.64.*',3,0)\n") | |
1537 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (24,'.1.3.6.1.4.1.45.3.53.*',3,0)\n") | |
1538 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (25,'.1.3.6.1.4.1.45.3.59.*',3,0)\n") | |
1539 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (26,'.1.3.6.1.4.1.45.3.39.*',3,0)\n") | |
1540 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (27,'.1.3.6.1.4.1.45.3.65.*',3,0)\n") | |
1541 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (28,'.1.3.6.1.4.1.45.3.66.*',3,0)\n") | |
1542 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (29,'.1.3.6.1.4.1.45.3.44.*',4,0)\n") | |
1543 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (30,'.1.3.6.1.4.1.45.3.47.*',4,0)\n") | |
1544 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (31,'.1.3.6.1.4.1.45.3.48.*',4,0)\n") | |
1545 | _T("<END>"); | |
1546 | ||
1547 | if (!SQLBatch(m_szBatch)) | |
1548 | if (!g_bIgnoreErrors) | |
1549 | return FALSE; | |
1550 | ||
1551 | if (!SQLQuery(_T("UPDATE config SET var_value='64' WHERE var_name='DBFormatVersion'"))) | |
1552 | if (!g_bIgnoreErrors) | |
1553 | return FALSE; | |
1554 | ||
1555 | return TRUE; | |
1556 | } | |
1557 | ||
1558 | ||
1559 | // | |
1560 | // Upgrade from V62 to V63 | |
1561 | // | |
1562 | ||
31cc1924 | 1563 | static BOOL H_UpgradeFromV62(int currVersion, int newVersion) |
5039dede AK |
1564 | { |
1565 | static TCHAR m_szBatch[] = | |
1566 | _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ") | |
1567 | _T("VALUES (45,'SYS_IF_UNKNOWN',1,1,") | |
1568 | _T("'Interface \"%2\" changed state to UNKNOWN (IP Addr: %3/%4, IfIndex: %5)',") | |
1569 | _T("'Generated when interface goes to unknown state.#0D#0A") | |
1570 | _T("Please note that source of event is node, not an interface itself.#0D#0A") | |
1571 | _T("Parameters:#0D#0A 1) Interface object ID#0D#0A 2) Interface name#0D#0A") | |
1572 | _T(" 3) Interface IP address#0D#0A 4) Interface netmask#0D#0A") | |
1573 | _T(" 5) Interface index')\n") | |
1574 | _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ") | |
1575 | _T("VALUES (46,'SYS_IF_DISABLED',0,1,") | |
1576 | _T("'Interface \"%2\" disabled (IP Addr: %3/%4, IfIndex: %5)',") | |
1577 | _T("'Generated when interface administratively disabled.#0D#0A") | |
1578 | _T("Please note that source of event is node, not an interface itself.#0D#0A") | |
1579 | _T("Parameters:#0D#0A 1) Interface object ID#0D#0A 2) Interface name#0D#0A") | |
1580 | _T(" 3) Interface IP address#0D#0A 4) Interface netmask#0D#0A") | |
1581 | _T(" 5) Interface index')\n") | |
1582 | _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ") | |
1583 | _T("VALUES (47,'SYS_IF_TESTING',0,1,") | |
1584 | _T("'Interface \"%2\" is testing (IP Addr: %3/%4, IfIndex: %5)',") | |
1585 | _T("'Generated when interface goes to testing state.#0D#0A") | |
1586 | _T("Please note that source of event is node, not an interface itself.#0D#0A") | |
1587 | _T("Parameters:#0D#0A 1) Interface object ID#0D#0A 2) Interface name#0D#0A") | |
1588 | _T(" 3) Interface IP address#0D#0A 4) Interface netmask#0D#0A") | |
1589 | _T(" 5) Interface index')\n") | |
1590 | _T("<END>"); | |
1591 | ||
1592 | if (!SQLBatch(m_szBatch)) | |
1593 | if (!g_bIgnoreErrors) | |
1594 | return FALSE; | |
1595 | ||
1596 | if (!SQLQuery(_T("UPDATE config SET var_value='63' WHERE var_name='DBFormatVersion'"))) | |
1597 | if (!g_bIgnoreErrors) | |
1598 | return FALSE; | |
1599 | ||
1600 | return TRUE; | |
1601 | } | |
1602 | ||
1603 | ||
1604 | // | |
1605 | // Upgrade from V61 to V62 | |
1606 | // | |
1607 | ||
31cc1924 | 1608 | static BOOL H_UpgradeFromV61(int currVersion, int newVersion) |
5039dede AK |
1609 | { |
1610 | static TCHAR m_szBatch[] = | |
1611 | _T("UPDATE event_policy SET alarm_key=alarm_ack_key WHERE alarm_severity=6\n") | |
1612 | _T("ALTER TABLE event_policy DROP COLUMN alarm_ack_key\n") | |
1613 | _T("ALTER TABLE event_policy ADD alarm_timeout integer\n") | |
1614 | _T("ALTER TABLE event_policy ADD alarm_timeout_event integer\n") | |
1615 | _T("UPDATE event_policy SET alarm_timeout=0,alarm_timeout_event=43\n") | |
1616 | _T("ALTER TABLE alarms ADD timeout integer\n") | |
1617 | _T("ALTER TABLE alarms ADD timeout_event integer\n") | |
1618 | _T("UPDATE alarms SET timeout=0,timeout_event=43\n") | |
1619 | _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ") | |
1620 | _T("VALUES (43,'SYS_ALARM_TIMEOUT',1,1,'Alarm timeout expired (ID: %1; Text: %2)',") | |
1621 | _T("'Generated when alarm timeout expires.#0D#0AParameters:#0D#0A") | |
1622 | _T(" 1) Alarm ID#0D#0A 2) Alarm message#0D#0A 3) Alarm key#0D#0A 4) Event code')\n") | |
1623 | _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ") | |
1624 | _T("VALUES (44,'SYS_LOG_RECORD_MATCHED',1,1,") | |
1625 | _T("'Log record matched (Policy: %1; File: %2; Record: %4)',") | |
1626 | _T("'Default event for log record match.#0D#0AParameters:#0D#0A") | |
1627 | _T(" 1) Policy name#0D#0A 2) Log file name#0D#0A 3) Matching regular expression#0D#0A") | |
1628 | _T(" 4) Matched record#0D#0A 5 .. 9) Reserved#0D#0A") | |
1629 | _T(" 10 .. 99) Substrings extracted by regular expression')\n") | |
1630 | _T("<END>"); | |
1631 | ||
1632 | if (!SQLBatch(m_szBatch)) | |
1633 | if (!g_bIgnoreErrors) | |
1634 | return FALSE; | |
1635 | ||
1636 | if (!CreateTable(_T("CREATE TABLE lpp_groups (") | |
1637 | _T("lpp_group_id integer not null,") | |
1638 | _T("lpp_group_name varchar(63) not null,") | |
1639 | _T("parent_group integer not null,") | |
1640 | _T("PRIMARY KEY(lpp_group_id))"))) | |
1641 | if (!g_bIgnoreErrors) | |
1642 | return FALSE; | |
1643 | ||
1644 | if (!CreateTable(_T("CREATE TABLE lpp (") | |
1645 | _T("lpp_id integer not null,") | |
1646 | _T("lpp_group_id integer not null,") | |
1647 | _T("lpp_name varchar(63) not null,") | |
1648 | _T("lpp_version integer not null,") | |
1649 | _T("lpp_flags integer not null,") | |
1650 | _T("PRIMARY KEY(lpp_id))"))) | |
1651 | if (!g_bIgnoreErrors) | |
1652 | return FALSE; | |
1653 | ||
1654 | if (!CreateTable(_T("CREATE TABLE lpp_associations (") | |
1655 | _T("lpp_id integer not null,") | |
1656 | _T("node_id integer not null,") | |
1657 | _T("log_file varchar(255) not null)"))) | |
1658 | if (!g_bIgnoreErrors) | |
1659 | return FALSE; | |
1660 | ||
1661 | if (!CreateTable(_T("CREATE TABLE lpp_rulesets (") | |
1662 | _T("ruleset_id integer not null,") | |
1663 | _T("ruleset_name varchar(63),") | |
1664 | _T("PRIMARY KEY(ruleset_id))"))) | |
1665 | if (!g_bIgnoreErrors) | |
1666 | return FALSE; | |
1667 | ||
1668 | if (!CreateTable(_T("CREATE TABLE lpp_rules (") | |
1669 | _T("lpp_id integer not null,") | |
1670 | _T("rule_number integer not null,") | |
1671 | _T("ruleset_id integer not null,") | |
1672 | _T("msg_id_start integer not null,") | |
1673 | _T("msg_id_end integer not null,") | |
1674 | _T("severity integer not null,") | |
1675 | _T("source_name varchar(255) not null,") | |
1676 | _T("msg_text_regexp varchar(255) not null,") | |
1677 | _T("event_code integer not null,") | |
1678 | _T("PRIMARY KEY(lpp_id,rule_number))"))) | |
1679 | if (!g_bIgnoreErrors) | |
1680 | return FALSE; | |
1681 | ||
1682 | if (!SQLQuery(_T("UPDATE config SET var_value='62' WHERE var_name='DBFormatVersion'"))) | |
1683 | if (!g_bIgnoreErrors) | |
1684 | return FALSE; | |
1685 | ||
1686 | return TRUE; | |
1687 | } | |
1688 | ||
1689 | ||
1690 | // | |
1691 | // Upgrade from V60 to V61 | |
1692 | // | |
1693 | ||
31cc1924 | 1694 | static BOOL H_UpgradeFromV60(int currVersion, int newVersion) |
5039dede AK |
1695 | { |
1696 | static TCHAR m_szBatch[] = | |
1697 | _T("DELETE FROM object_tools WHERE tool_id=14\n") | |
1698 | _T("DELETE FROM object_tools_table_columns WHERE tool_id=14\n") | |
1699 | _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text) ") | |
1700 | _T("VALUES (14,'&Info->Topology table (Nortel)',2,'Topology table',1,' ','Show topology table (Nortel protocol)','#00')\n") | |
1701 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ") | |
1702 | _T("VALUES (14,0,'Peer IP','.1.3.6.1.4.1.45.1.6.13.2.1.1.3',3,0)\n") | |
1703 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ") | |
1704 | _T("VALUES (14,1,'Peer MAC','.1.3.6.1.4.1.45.1.6.13.2.1.1.5',4,0)\n") | |
1705 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ") | |
1706 | _T("VALUES (14,2,'Slot','.1.3.6.1.4.1.45.1.6.13.2.1.1.1',1,0)\n") | |
1707 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ") | |
1708 | _T("VALUES (14,3,'Port','.1.3.6.1.4.1.45.1.6.13.2.1.1.2',1,0)\n") | |
1709 | _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text) ") | |
1710 | _T("VALUES (17,'&Info->AR&P cache (SNMP)',2,'ARP Cache',1,' ','Show ARP cache','#00')\n") | |
1711 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ") | |
1712 | _T("VALUES (17,0,'IP Address','.1.3.6.1.2.1.4.22.1.3',3,0)\n") | |
1713 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ") | |
1714 | _T("VALUES (17,1,'MAC Address','.1.3.6.1.2.1.4.22.1.2',4,0)\n") | |
1715 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ") | |
1716 | _T("VALUES (17,2,'Interface','.1.3.6.1.2.1.4.22.1.1',5,0)\n") | |
1717 | _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text) ") | |
1718 | _T("VALUES (18,'&Info->AR&P cache (Agent)',3,") | |
1719 | _T("'ARP Cache#7FNet.ArpCache#7F(.*) (.*) (.*)',2,' ','Show ARP cache','#00')\n") | |
1720 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ") | |
1721 | _T("VALUES (18,0,'IP Address','.1.3.6.1.2.1.4.22.1.3',0,2)\n") | |
1722 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ") | |
1723 | _T("VALUES (18,1,'MAC Address','.1.3.6.1.2.1.4.22.1.2',0,1)\n") | |
1724 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ") | |
1725 | _T("VALUES (18,2,'Interface','.1.3.6.1.2.1.4.22.1.1',5,3)\n") | |
1726 | _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text) ") | |
1727 | _T("VALUES (19,'&Info->&Routing table (SNMP)',2,'Routing Table',1,' ','Show IP routing table','#00')\n") | |
1728 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ") | |
1729 | _T("VALUES (19,0,'Destination','.1.3.6.1.2.1.4.21.1.1',3,0)\n") | |
1730 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ") | |
1731 | _T("VALUES (19,1,'Mask','.1.3.6.1.2.1.4.21.1.11',3,0)\n") | |
1732 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ") | |
1733 | _T("VALUES (19,2,'Next hop','.1.3.6.1.2.1.4.21.1.7',3,0)\n") | |
1734 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ") | |
1735 | _T("VALUES (19,3,'Metric','.1.3.6.1.2.1.4.21.1.3',1,0)\n") | |
1736 | _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ") | |
1737 | _T("VALUES (19,4,'Interface','.1.3.6.1.2.1.4.21.1.2',5,0)\n") | |
1738 | _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (17,-2147483648)\n") | |
1739 | _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (18,-2147483648)\n") | |
1740 | _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (19,-2147483648)\n") | |
1741 | _T("<END>"); | |
1742 | ||
1743 | if (!SQLBatch(m_szBatch)) | |
1744 | if (!g_bIgnoreErrors) | |
1745 | return FALSE; | |
1746 | ||
1747 | if (!CreateConfigParam(_T("TopologyExpirationTime"), _T("900"), 1, 0)) | |
1748 | if (!g_bIgnoreErrors) | |
1749 | return FALSE; | |
1750 | ||
1751 | if (!CreateConfigParam(_T("TopologyDiscoveryRadius"), _T("3"), 1, 0)) | |
1752 | if (!g_bIgnoreErrors) | |
1753 | return FALSE; | |
1754 | ||
1755 | if (!SQLQuery(_T("UPDATE config SET var_value='61' WHERE var_name='DBFormatVersion'"))) | |
1756 | if (!g_bIgnoreErrors) | |
1757 | return FALSE; | |
1758 | ||
1759 | return TRUE; | |
1760 | } | |
1761 | ||
1762 | ||
1763 | // | |
1764 | // Upgrade from V59 to V60 | |
1765 | // | |
1766 | ||
31cc1924 | 1767 | static BOOL H_UpgradeFromV59(int currVersion, int newVersion) |
5039dede AK |
1768 | { |
1769 | if (!CreateTable(_T("CREATE TABLE certificates (") | |
1770 | _T("cert_id integer not null,") | |
1771 | _T("cert_type integer not null,") | |
1772 | _T("cert_data $SQL:TEXT not null,") | |
1773 | _T("subject $SQL:TEXT not null,") | |
1774 | _T("comments $SQL:TEXT not null,") | |
1775 | _T("PRIMARY KEY(cert_id))"))) | |
1776 | if (!g_bIgnoreErrors) | |
1777 | return FALSE; | |
1778 | ||
1779 | if (!CreateConfigParam(_T("SNMPRequestTimeout"), _T("2000"), 1, 1)) | |
1780 | if (!g_bIgnoreErrors) | |
1781 | return FALSE; | |
1782 | ||
1783 | if (!SQLQuery(_T("UPDATE config SET var_value='60' WHERE var_name='DBFormatVersion'"))) | |
1784 | if (!g_bIgnoreErrors) | |
1785 | return FALSE; | |
1786 | ||
1787 | return TRUE; | |
1788 | } | |
1789 | ||
1790 | ||
1791 | // | |
1792 | // Upgrade from V58 to V59 | |
1793 | // | |
1794 | ||
31cc1924 | 1795 | static BOOL H_UpgradeFromV58(int currVersion, int newVersion) |
5039dede AK |
1796 | { |
1797 | static TCHAR m_szBatch[] = | |
1798 | _T("ALTER TABLE users ADD cert_mapping_method integer\n") | |
1799 | _T("ALTER TABLE users ADD cert_mapping_data $SQL:TEXT\n") | |
1800 | _T("UPDATE users SET cert_mapping_method=0\n") | |
1801 | _T("UPDATE users SET cert_mapping_data='#00'\n") | |
1802 | _T("<END>"); | |
1803 | ||
1804 | if (!SQLBatch(m_szBatch)) | |
1805 | if (!g_bIgnoreErrors) | |
1806 | return FALSE; | |
1807 | ||
1808 | if (!CreateConfigParam(_T("InternalCA"), _T("0"), 1, 1)) | |
1809 | if (!g_bIgnoreErrors) | |
1810 | return FALSE; | |
1811 | ||
1812 | if (!SQLQuery(_T("UPDATE config SET var_value='59' WHERE var_name='DBFormatVersion'"))) | |
1813 | if (!g_bIgnoreErrors) | |
1814 | return FALSE; | |
1815 | ||
1816 | return TRUE; | |
1817 | } | |
1818 | ||
1819 | ||
1820 | // | |
1821 | // Upgrade from V57 to V58 | |
1822 | // | |
1823 | ||
31cc1924 | 1824 | static BOOL H_UpgradeFromV57(int currVersion, int newVersion) |
5039dede AK |
1825 | { |
1826 | static TCHAR m_szBatch[] = | |
1827 | _T("ALTER TABLE object_properties ADD is_system integer\n") | |
1828 | _T("UPDATE object_properties SET is_system=0\n") | |
1829 | _T("<END>"); | |
1830 | ||
1831 | if (!SQLBatch(m_szBatch)) | |
1832 | if (!g_bIgnoreErrors) | |
1833 | return FALSE; | |
1834 | ||
1835 | if (!CreateTable(_T("CREATE TABLE graphs (") | |
1836 | _T("graph_id integer not null,") | |
1837 | _T("owner_id integer not null,") | |
1838 | _T("name varchar(255) not null,") | |
1839 | _T("config $SQL:TEXT not null,") | |
1840 | _T("PRIMARY KEY(graph_id))"))) | |
1841 | if (!g_bIgnoreErrors) | |
1842 | return FALSE; | |
1843 | ||
1844 | if (!CreateTable(_T("CREATE TABLE graph_acl (") | |
1845 | _T("graph_id integer not null,") | |
1846 | _T("user_id integer not null,") | |
1847 | _T("user_rights integer not null,") | |
1848 | _T("PRIMARY KEY(graph_id,user_id))"))) | |
1849 | if (!g_bIgnoreErrors) | |
1850 | return FALSE; | |
1851 | ||
1852 | if (!SQLQuery(_T("UPDATE config SET var_value='58' WHERE var_name='DBFormatVersion'"))) | |
1853 | if (!g_bIgnoreErrors) | |
1854 | return FALSE; | |
1855 | ||
1856 | return TRUE; | |
1857 | } | |
1858 | ||
1859 | ||
1860 | // | |
1861 | // Upgrade from V56 to V57 | |
1862 | // | |
1863 | ||
31cc1924 | 1864 | static BOOL H_UpgradeFromV56(int currVersion, int newVersion) |
5039dede AK |
1865 | { |
1866 | static TCHAR m_szBatch[] = | |
1867 | _T("ALTER TABLE items ADD resource_id integer\n") | |
1868 | _T("UPDATE items SET resource_id=0\n") | |
1869 | _T("ALTER TABLE nodes ADD snmp_proxy integer\n") | |
1870 | _T("UPDATE nodes SET snmp_proxy=0\n") | |
1871 | _T("<END>"); | |
1872 | ||
1873 | if (!SQLBatch(m_szBatch)) | |
1874 | if (!g_bIgnoreErrors) | |
1875 | return FALSE; | |
1876 | ||
1877 | if (!SQLQuery(_T("UPDATE config SET var_value='57' WHERE var_name='DBFormatVersion'"))) | |
1878 | if (!g_bIgnoreErrors) | |
1879 | return FALSE; | |
1880 | ||
1881 | return TRUE; | |
1882 | } | |
1883 | ||
1884 | ||
1885 | // | |
1886 | // Upgrade from V55 to V56 | |
1887 | // | |
1888 | ||
31cc1924 | 1889 | static BOOL H_UpgradeFromV55(int currVersion, int newVersion) |
5039dede AK |
1890 | { |
1891 | static TCHAR m_szBatch[] = | |
1892 | _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES") | |
1893 | _T(" (38,'SYS_CLUSTER_RESOURCE_MOVED',1,1,") | |
1894 | _T("'Cluster resource \"%2\" moved from node %4 to node %6',") | |
1895 | _T("'Generated when cluster resource moved between nodes.#0D#0A") | |
1896 | _T("Parameters:#0D#0A 1) Resource ID#0D#0A") | |
1897 | _T(" 2) Resource name#0D#0A 3) Previous owner node ID#0D#0A") | |
1898 | _T(" 4) Previous owner node name#0D#0A 5) New owner node ID#0D#0A") | |
1899 | _T(" 6) New owner node name')\n") | |
1900 | _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES") | |
1901 | _T(" (39,'SYS_CLUSTER_RESOURCE_DOWN',3,1,") | |
1902 | _T("'Cluster resource \"%2\" is down (last owner was %4)',") | |
1903 | _T("'Generated when cluster resource goes down.#0D#0A") | |
1904 | _T("Parameters:#0D#0A 1) Resource ID#0D#0A 2) Resource name#0D#0A") | |
1905 | _T(" 3) Last owner node ID#0D#0A 4) Last owner node name')\n") | |
1906 | _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES") | |
1907 | _T(" (40,'SYS_CLUSTER_RESOURCE_UP',0,1,") | |
1908 | _T("'Cluster resource \"%2\" is up (new owner is %4)',") | |
1909 | _T("'Generated when cluster resource goes up.#0D#0A") | |
1910 | _T("Parameters:#0D#0A 1) Resource ID#0D#0A 2) Resource name#0D#0A") | |
1911 | _T(" 3) New owner node ID#0D#0A 4) New owner node name')\n") | |
1912 | _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES") | |
1913 | _T(" (41,'SYS_CLUSTER_DOWN',4,1,'Cluster is down',") | |
1914 | _T("'Generated when cluster goes down.#0D#0AParameters:#0D#0A No message-specific parameters')\n") | |
1915 | _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES") | |
1916 | _T(" (42,'SYS_CLUSTER_UP',0,1,'Cluster is up',") | |
1917 | _T("'Generated when cluster goes up.#0D#0AParameters:#0D#0A No message-specific parameters')\n") | |
1918 | _T("<END>"); | |
1919 | ||
1920 | if (!SQLBatch(m_szBatch)) | |
1921 | if (!g_bIgnoreErrors) | |
1922 | return FALSE; | |
1923 | ||
1924 | if (!CreateTable(_T("CREATE TABLE cluster_resources (") | |
1925 | _T("cluster_id integer not null,") | |
1926 | _T("resource_id integer not null,") | |
1927 | _T("resource_name varchar(255) not null,") | |
1928 | _T("ip_addr varchar(15) not null,") | |
1929 | _T("PRIMARY KEY(cluster_id,resource_id))"))) | |
1930 | if (!g_bIgnoreErrors) | |
1931 | return FALSE; | |
1932 | ||
1933 | if (!SQLQuery(_T("UPDATE config SET var_value='56' WHERE var_name='DBFormatVersion'"))) | |
1934 | if (!g_bIgnoreErrors) | |
1935 | return FALSE; | |
1936 | ||
1937 | return TRUE; | |
1938 | } | |
1939 | ||
1940 | ||
1941 | // | |
1942 | // Upgrade from V54 to V55 | |
1943 | // | |
1944 | ||
31cc1924 | 1945 | static BOOL H_UpgradeFromV54(int currVersion, int newVersion) |
5039dede AK |
1946 | { |
1947 | static TCHAR m_szBatch[] = | |
1948 | _T("ALTER TABLE containers DROP COLUMN description\n") | |
1949 | _T("ALTER TABLE nodes DROP COLUMN description\n") | |
1950 | _T("ALTER TABLE templates DROP COLUMN description\n") | |
1951 | _T("ALTER TABLE zones DROP COLUMN description\n") | |
1952 | _T("INSERT INTO images (image_id,name,file_name_png,file_hash_png,") | |
1953 | _T("file_name_ico,file_hash_ico) VALUES (16,'Obj.Cluster',") | |
1954 | _T("'cluster.png','<invalid_hash>','cluster.ico','<invalid_hash>')\n") | |
1955 | _T("INSERT INTO default_images (object_class,image_id) VALUES (14,16)\n") | |
1956 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ") | |
1957 | _T("VALUES (12,'.1.3.6.1.4.1.45.3.46.*',3,0)\n") | |
1958 | _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ") | |
1959 | _T("VALUES (13,'.1.3.6.1.4.1.45.3.52.*',3,0)\n") | |
1960 | _T("<END>"); | |
1961 | ||
1962 | if (!SQLBatch(m_szBatch)) | |
1963 | if (!g_bIgnoreErrors) | |
1964 | return FALSE; | |
1965 | ||
1966 | if (!CreateTable(_T("CREATE TABLE clusters (") | |
1967 | _T("id integer not null,") | |
1968 | _T("cluster_type integer not null,") | |
1969 | _T("PRIMARY KEY(id))"))) | |
1970 | if (!g_bIgnoreErrors) | |
1971 | return FALSE; | |
1972 | ||
1973 | if (!CreateTable(_T("CREATE TABLE cluster_members (") | |
1974 | _T("cluster_id integer not null,") | |
1975 | _T("node_id integer not null,") | |
1976 | _T("PRIMARY KEY(cluster_id,node_id))"))) | |
1977 | if (!g_bIgnoreErrors) | |
1978 | return FALSE; | |
1979 | ||
1980 | if (!CreateTable(_T("CREATE TABLE cluster_sync_subnets (") | |
1981 | _T("cluster_id integer not null,") | |
1982 | _T("subnet_addr varchar(15) not null,") | |
1983 | _T("subnet_mask varchar(15) not null,") | |
1984 | _T("PRIMARY KEY(cluster_id,subnet_addr))"))) | |
1985 | if (!g_bIgnoreErrors) | |
1986 | return FALSE; | |
1987 | ||
1988 | if (!CreateConfigParam(_T("WindowsConsoleUpgradeURL"), _T("http://www.netxms.org/download/netxms-%version%.exe"), 1, 0)) | |
1989 | if (!g_bIgnoreErrors) | |
1990 | return FALSE; | |
1991 | ||
1992 | if (!SQLQuery(_T("UPDATE config SET var_value='55' WHERE var_name='DBFormatVersion'"))) | |
1993 | if (!g_bIgnoreErrors) | |
1994 | return FALSE; | |
1995 | ||
1996 | return TRUE; | |
1997 | } | |
1998 | ||
1999 | ||
2000 | // | |
2001 | // Upgrade from V53 to V54 | |
2002 | // | |
2003 | ||
31cc1924 | 2004 | static BOOL H_UpgradeFromV53(int currVersion, int newVersion) |
5039dede AK |
2005 | { |
2006 | static TCHAR m_szBatch[] = | |
2007 | _T("CREATE INDEX idx_address_lists_list_type ON address_lists(list_type)\n") | |
2008 | _T("DELETE FROM config WHERE var_name='EnableAccessControl'\n") | |
2009 | _T("DELETE FROM config WHERE var_name='EnableEventAccessControl'\n") | |
2010 | _T("<END>"); | |
2011 | ||
2012 | if (!CreateTable(_T("CREATE TABLE address_lists (") | |
2013 | _T("list_type integer not null,") | |
2014 | _T("addr_type integer not null,") | |
2015 | _T("addr1 varchar(15) not null,") | |
2016 | _T("addr2 varchar(15) not null)"))) | |
2017 | if (!g_bIgnoreErrors) | |
2018 | return FALSE; | |
2019 | ||
2020 | if (!SQLBatch(m_szBatch)) | |
2021 | if (!g_bIgnoreErrors) | |
2022 | return FALSE; | |
2023 | ||
2024 | if (!CreateConfigParam(_T("ActiveNetworkDiscovery"), _T("0"), 1, 1)) | |
2025 | if (!g_bIgnoreErrors) | |
2026 | return FALSE; | |
2027 | ||
2028 | if (!CreateConfigParam(_T("ActiveDiscoveryInterval"), _T("7200"), 1, 1)) | |
2029 | if (!g_bIgnoreErrors) | |
2030 | return FALSE; | |
2031 | ||
2032 | if (!CreateConfigParam(_T("DiscoveryFilterFlags"), _T("0"), 1, 0)) | |
2033 | if (!g_bIgnoreErrors) | |
2034 | return FALSE; | |
2035 | ||
2036 | if (!SQLQuery(_T("UPDATE config SET var_value='54' WHERE var_name='DBFormatVersion'"))) | |
2037 | if (!g_bIgnoreErrors) | |
2038 | return FALSE; | |
2039 | ||
2040 | return TRUE; | |
2041 | } | |
2042 | ||
2043 | ||
2044 | // | |
2045 | // Upgrade from V52 to V53 | |
2046 | // | |
2047 | ||
31cc1924 | 2048 | static BOOL H_UpgradeFromV52(int currVersion, int newVersion) |
5039dede AK |
2049 | { |
2050 | DB_RESULT hResult; | |
2051 | int i, nCount; | |
2052 | DWORD dwId; | |
2053 | TCHAR szQuery[1024]; | |
2054 | static const TCHAR *pszNewIdx[] = | |
2055 | { | |
2056 | _T("CREATE INDEX idx_idata_%d_id_timestamp ON idata_%d(item_id,idata_timestamp)"), // MySQL | |
2057 | _T("CREATE INDEX idx_idata_%d_timestamp_id ON idata_%d(idata_timestamp,item_id)"), // POstgreSQL | |
2058 | _T("CREATE CLUSTERED INDEX idx_idata_%d_id_timestamp ON idata_%d(item_id,idata_timestamp)"), // MS SQL | |
2059 | _T("CREATE INDEX idx_idata_%d_timestamp_id ON idata_%d(idata_timestamp,item_id)"), // Oracle | |
2060 | _T("CREATE INDEX idx_idata_%d_timestamp_id ON idata_%d(idata_timestamp,item_id)") // SQLite | |
2061 | }; | |
2062 | ||
2063 | hResult = SQLSelect(_T("SELECT id FROM nodes")); | |
2064 | if (hResult == NULL) | |
2065 | return FALSE; | |
2066 | ||
2067 | _tprintf(_T("Reindexing database:\n")); | |
2068 | nCount = DBGetNumRows(hResult); | |
2069 | for(i = 0; i < nCount; i++) | |
2070 | { | |
2071 | dwId = DBGetFieldULong(hResult, i, 0); | |
2072 | _tprintf(" * idata_%d\n", dwId); | |
2073 | ||
2074 | // Drop old indexes | |
2075 | _stprintf(szQuery, _T("DROP INDEX idx_idata_%d_timestamp"), dwId); | |
2076 | DBQuery(g_hCoreDB, szQuery); | |
2077 | ||
2078 | // Create new index | |
2079 | _stprintf(szQuery, pszNewIdx[g_iSyntax], dwId, dwId); | |
2080 | SQLQuery(szQuery); | |
2081 | } | |
2082 | ||
2083 | DBFreeResult(hResult); | |
2084 | ||
2085 | // Update index creation command | |
2086 | DBQuery(g_hCoreDB, _T("DELETE FROM config WHERE var_name='IDataIndexCreationCommand_1'")); | |
2087 | if (!CreateConfigParam(_T("IDataIndexCreationCommand_1"), pszNewIdx[g_iSyntax], 0, 1)) | |
2088 | if (!g_bIgnoreErrors) | |
2089 | return FALSE; | |
2090 | ||
2091 | if (!SQLQuery(_T("UPDATE config SET var_value='53' WHERE var_name='DBFormatVersion'"))) | |
2092 | if (!g_bIgnoreErrors) | |
2093 | return FALSE; | |
2094 | ||
2095 | return TRUE; | |
2096 | } | |
2097 | ||
2098 | ||
2099 | // | |
2100 | // Upgrade from V51 to V52 | |
2101 | // | |
2102 | ||
31cc1924 | 2103 | static BOOL H_UpgradeFromV51(int currVersion, int newVersion) |
5039dede AK |
2104 | { |
2105 | static TCHAR m_szBatch[] = | |
2106 | "UPDATE object_tools SET tool_data='Configured ICMP targets#7FICMP.TargetList#7F^(.*) (.*) (.*) (.*) (.*)' WHERE tool_id=12\n" | |
2107 | "UPDATE object_tools_table_columns SET col_number=4 WHERE col_number=3 AND tool_id=12\n" | |
2108 | "UPDATE object_tools_table_columns SET col_number=3 WHERE col_number=2 AND tool_id=12\n" | |
2109 | "UPDATE object_tools_table_columns SET col_substr=5 WHERE col_number=1 AND tool_id=12\n" | |
2110 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
2111 | "VALUES (12,2,'Packet size','',0,4)\n" | |
2112 | "INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text) " | |
2113 | "VALUES (16,'&Info->Active &user sessions',3," | |
2114 | "'Active User Sessions#7FSystem.ActiveUserSessions#7F^\"(.*)\" \"(.*)\" \"(.*)\"'," | |
2115 | "2,'','Show list of active user sessions','#00')\n" | |
2116 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
2117 | "VALUES (16,0,'User','',0,1)\n" | |
2118 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
2119 | "VALUES (16,1,'Terminal','',0,2)\n" | |
2120 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
2121 | "VALUES (16,2,'From','',0,3)\n" | |
2122 | "INSERT INTO object_tools_acl (tool_id,user_id) VALUES (16,-2147483648)\n" | |
2123 | "<END>"; | |
2124 | ||
2125 | if (!SQLBatch(m_szBatch)) | |
2126 | if (!g_bIgnoreErrors) | |
2127 | return FALSE; | |
2128 | ||
2129 | if (!CreateConfigParam(_T("MailEncoding"), _T("iso-8859-1"), 1, 0)) | |
2130 | if (!g_bIgnoreErrors) | |
2131 | return FALSE; | |
2132 | ||
2133 | if (!SQLQuery(_T("UPDATE config SET var_value='52' WHERE var_name='DBFormatVersion'"))) | |
2134 | if (!g_bIgnoreErrors) | |
2135 | return FALSE; | |
2136 | ||
2137 | return TRUE; | |
2138 | } | |
2139 | ||
2140 | ||
2141 | // | |
2142 | // Upgrade from V50 to V51 | |
2143 | // | |
2144 | ||
31cc1924 | 2145 | static BOOL H_UpgradeFromV50(int currVersion, int newVersion) |
5039dede AK |
2146 | { |
2147 | static TCHAR m_szBatch[] = | |
2148 | "ALTER TABLE event_groups ADD range_start integer\n" | |
2149 | "ALTER TABLE event_groups ADD range_END integer\n" | |
2150 | "UPDATE event_groups SET range_start=0,range_end=0\n" | |
2151 | "<END>"; | |
2152 | ||
2153 | if (!SQLBatch(m_szBatch)) | |
2154 | if (!g_bIgnoreErrors) | |
2155 | return FALSE; | |
2156 | ||
2157 | if (!SQLQuery(_T("UPDATE config SET var_value='51' WHERE var_name='DBFormatVersion'"))) | |
2158 | if (!g_bIgnoreErrors) | |
2159 | return FALSE; | |
2160 | ||
2161 | return TRUE; | |
2162 | } | |
2163 | ||
2164 | ||
2165 | // | |
2166 | // Upgrade from V49 to V50 | |
2167 | // | |
2168 | ||
31cc1924 | 2169 | static BOOL H_UpgradeFromV49(int currVersion, int newVersion) |
5039dede AK |
2170 | { |
2171 | static TCHAR m_szBatch[] = | |
2172 | "ALTER TABLE object_tools ADD confirmation_text varchar(255)\n" | |
2173 | "UPDATE object_tools SET confirmation_text='#00'\n" | |
2174 | "UPDATE object_tools SET flags=10 WHERE tool_id=1 OR tool_id=2 OR tool_id=4\n" | |
2175 | "UPDATE object_tools SET confirmation_text='Host #25OBJECT_NAME#25 (#25OBJECT_IP_ADDR#25) will be shut down. Are you sure?' WHERE tool_id=1\n" | |
2176 | "UPDATE object_tools SET confirmation_text='Host #25OBJECT_NAME#25 (#25OBJECT_IP_ADDR#25) will be restarted. Are you sure?' WHERE tool_id=2\n" | |
2177 | "UPDATE object_tools SET confirmation_text='NetXMS agent on host #25OBJECT_NAME#25 (#25OBJECT_IP_ADDR#25) will be restarted. Are you sure?' WHERE tool_id=4\n" | |
2178 | "<END>"; | |
2179 | ||
2180 | if (!SQLBatch(m_szBatch)) | |
2181 | if (!g_bIgnoreErrors) | |
2182 | return FALSE; | |
2183 | ||
2184 | if (!SQLQuery(_T("UPDATE config SET var_value='50' WHERE var_name='DBFormatVersion'"))) | |
2185 | if (!g_bIgnoreErrors) | |
2186 | return FALSE; | |
2187 | ||
2188 | return TRUE; | |
2189 | } | |
2190 | ||
2191 | ||
2192 | // | |
2193 | // Upgrade from V48 to V49 | |
2194 | // | |
2195 | ||
31cc1924 | 2196 | static BOOL H_UpgradeFromV48(int currVersion, int newVersion) |
5039dede AK |
2197 | { |
2198 | static TCHAR m_szBatch[] = | |
2199 | "ALTER TABLE items ADD all_thresholds integer\n" | |
2200 | "UPDATE items SET all_thresholds=0\n" | |
2201 | "ALTER TABLE thresholds ADD rearm_event_code integer\n" | |
2202 | "UPDATE thresholds SET rearm_event_code=18\n" | |
2203 | "<END>"; | |
2204 | ||
2205 | if (!SQLBatch(m_szBatch)) | |
2206 | if (!g_bIgnoreErrors) | |
2207 | return FALSE; | |
2208 | ||
2209 | if (!SQLQuery(_T("UPDATE config SET var_value='49' WHERE var_name='DBFormatVersion'"))) | |
2210 | if (!g_bIgnoreErrors) | |
2211 | return FALSE; | |
2212 | ||
2213 | return TRUE; | |
2214 | } | |
2215 | ||
2216 | ||
2217 | // | |
2218 | // Upgrade from V47 to V48 | |
2219 | // | |
2220 | ||
31cc1924 | 2221 | static BOOL H_UpgradeFromV47(int currVersion, int newVersion) |
5039dede AK |
2222 | { |
2223 | static TCHAR m_szBatch[] = | |
2224 | "ALTER TABLE event_policy ADD script $SQL:TEXT\n" | |
2225 | "UPDATE event_policy SET script='#00'\n" | |
2226 | "<END>"; | |
2227 | ||
2228 | if (!SQLBatch(m_szBatch)) | |
2229 | if (!g_bIgnoreErrors) | |
2230 | return FALSE; | |
2231 | ||
2232 | if (!CreateTable(_T("CREATE TABLE policy_time_range_list (") | |
2233 | _T("rule_id integer not null,") | |
2234 | _T("time_range_id integer not null,") | |
2235 | _T("PRIMARY KEY(rule_id,time_range_id))"))) | |
2236 | if (!g_bIgnoreErrors) | |
2237 | return FALSE; | |
2238 | ||
2239 | if (!CreateTable(_T("CREATE TABLE time_ranges (") | |
2240 | _T("time_range_id integer not null,") | |
2241 | _T("wday_mask integer not null,") | |
2242 | _T("mday_mask integer not null,") | |
2243 | _T("month_mask integer not null,") | |
2244 | _T("time_range varchar(255) not null,") | |
2245 | _T("PRIMARY KEY(time_range_id))"))) | |
2246 | if (!g_bIgnoreErrors) | |
2247 | return FALSE; | |
2248 | ||
2249 | if (!SQLQuery(_T("UPDATE config SET var_value='48' WHERE var_name='DBFormatVersion'"))) | |
2250 | if (!g_bIgnoreErrors) | |
2251 | return FALSE; | |
2252 | ||
2253 | return TRUE; | |
2254 | } | |
2255 | ||
2256 | ||
2257 | // | |
2258 | // Upgrade from V46 to V47 | |
2259 | // | |
2260 | ||
31cc1924 | 2261 | static BOOL H_UpgradeFromV46(int currVersion, int newVersion) |
5039dede AK |
2262 | { |
2263 | static TCHAR m_szBatch[] = | |
2264 | "ALTER TABLE object_properties ADD comments $SQL:TEXT\n" | |
2265 | "UPDATE object_properties SET comments='#00'\n" | |
2266 | "ALTER TABLE nodes DROP COLUMN discovery_flags\n" | |
2267 | "DROP TABLE alarm_notes\n" | |
2268 | "ALTER TABLE alarms ADD alarm_state integer\n" | |
2269 | "ALTER TABLE alarms ADD hd_state integer\n" | |
2270 | "ALTER TABLE alarms ADD hd_ref varchar(63)\n" | |
2271 | "ALTER TABLE alarms ADD creation_time integer\n" | |
2272 | "ALTER TABLE alarms ADD last_change_time integer\n" | |
2273 | "ALTER TABLE alarms ADD original_severity integer\n" | |
2274 | "ALTER TABLE alarms ADD current_severity integer\n" | |
2275 | "ALTER TABLE alarms ADD repeat_count integer\n" | |
2276 | "ALTER TABLE alarms ADD term_by integer\n" | |
2277 | "UPDATE alarms SET hd_state=0,hd_ref='#00',creation_time=alarm_timestamp," | |
2278 | "last_change_time=alarm_timestamp,original_severity=severity," | |
2279 | "current_severity=severity,repeat_count=1,term_by=ack_by\n" | |
2280 | "UPDATE alarms SET alarm_state=0 WHERE is_ack=0\n" | |
2281 | "UPDATE alarms SET alarm_state=2 WHERE is_ack<>0\n" | |
2282 | "ALTER TABLE alarms DROP COLUMN severity\n" | |
2283 | "ALTER TABLE alarms DROP COLUMN alarm_timestamp\n" | |
2284 | "ALTER TABLE alarms DROP COLUMN is_ack\n" | |
2285 | "ALTER TABLE thresholds ADD current_state integer\n" | |
2286 | "UPDATE thresholds SET current_state=0\n" | |
2287 | "<END>"; | |
2288 | static TCHAR m_szBatch2[] = | |
2289 | "CREATE INDEX idx_alarm_notes_alarm_id ON alarm_notes(alarm_id)\n" | |
2290 | "CREATE INDEX idx_alarm_change_log_alarm_id ON alarm_change_log(alarm_id)\n" | |
2291 | "<END>"; | |
2292 | ||
2293 | if (!SQLBatch(m_szBatch)) | |
2294 | if (!g_bIgnoreErrors) | |
2295 | return FALSE; | |
2296 | ||
2297 | if (!CreateTable(_T("CREATE TABLE alarm_notes (" | |
2298 | "note_id integer not null," | |
2299 | "alarm_id integer not null," | |
2300 | "change_time integer not null," | |
2301 | "user_id integer not null," | |
2302 | "note_text $SQL:TEXT not null," | |
2303 | "PRIMARY KEY(note_id))"))) | |
2304 | if (!g_bIgnoreErrors) | |
2305 | return FALSE; | |
2306 | ||
2307 | if (!CreateTable(_T("CREATE TABLE alarm_change_log (" | |
2308 | "change_id $SQL:INT64 not null," | |
2309 | "change_time integer not null," | |
2310 | "alarm_id integer not null," | |
2311 | "opcode integer not null," | |
2312 | "user_id integer not null," | |
2313 | "info_text $SQL:TEXT not null," | |
2314 | "PRIMARY KEY(change_id))"))) | |
2315 | if (!g_bIgnoreErrors) | |
2316 | return FALSE; | |
2317 | ||
2318 | if (!CreateTable(_T("CREATE TABLE alarm_grops (" | |
2319 | "alarm_group_id integer not null," | |
2320 | "group_name varchar(255) not null," | |
2321 | "PRIMARY KEY(alarm_group_id))"))) | |
2322 | if (!g_bIgnoreErrors) | |
2323 | return FALSE; | |
2324 | ||
2325 | if (!CreateTable(_T("CREATE TABLE alarm_group_map (" | |
2326 | "alarm_group_id integer not null," | |
2327 | "alarm_id integer not null," | |
2328 | "PRIMARY KEY(alarm_group_id,alarm_id))"))) | |
2329 | if (!g_bIgnoreErrors) | |
2330 | return FALSE; | |
2331 | ||
2332 | if (!SQLBatch(m_szBatch2)) | |
2333 | if (!g_bIgnoreErrors) | |
2334 | return FALSE; | |
2335 | ||
2336 | if (!SQLQuery(_T("UPDATE config SET var_value='47' WHERE var_name='DBFormatVersion'"))) | |
2337 | if (!g_bIgnoreErrors) | |
2338 | return FALSE; | |
2339 | ||
2340 | return TRUE; | |
2341 | } | |
2342 | ||
2343 | ||
2344 | // | |
2345 | // Upgrade from V45 to V46 | |
2346 | // | |
2347 | ||
31cc1924 | 2348 | static BOOL H_UpgradeFromV45(int currVersion, int newVersion) |
5039dede AK |
2349 | { |
2350 | static TCHAR m_szBatch[] = | |
2351 | "UPDATE object_tools_table_columns SET col_format=5 WHERE tool_id=5 AND col_number=1\n" | |
2352 | "INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) " | |
2353 | "VALUES (2,'.1.3.6.1.4.1.45.3.26.*',3,0)\n" | |
2354 | "INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) " | |
2355 | "VALUES (3,'.1.3.6.1.4.1.45.3.30.*',3,0)\n" | |
2356 | "INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) " | |
2357 | "VALUES (4,'.1.3.6.1.4.1.45.3.31.*',3,0)\n" | |
2358 | "INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) " | |
2359 | "VALUES (5,'.1.3.6.1.4.1.45.3.32.*',3,0)\n" | |
2360 | "INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) " | |
2361 | "VALUES (6,'.1.3.6.1.4.1.45.3.33.*',3,0)\n" | |
2362 | "INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) " | |
2363 | "VALUES (7,'.1.3.6.1.4.1.45.3.34.*',3,0)\n" | |
2364 | "INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) " | |
2365 | "VALUES (8,'.1.3.6.1.4.1.45.3.35.*',3,0)\n" | |
2366 | "INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) " | |
2367 | "VALUES (9,'.1.3.6.1.4.1.45.3.36.*',3,0)\n" | |
2368 | "INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) " | |
2369 | "VALUES (10,'.1.3.6.1.4.1.45.3.40.*',3,0)\n" | |
2370 | "INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) " | |
2371 | "VALUES (11,'.1.3.6.1.4.1.45.3.61.*',3,0)\n" | |
2372 | "INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description) " | |
2373 | "VALUES (14,'&Info->Topology table (Nortel)',2 ,'Topology table',1,'','Show topology table (Nortel protocol)')\n" | |
2374 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
2375 | "VALUES (14,0,'Peer IP','.1.3.6.1.4.1.45.1.6.13.2.1.1.3',3 ,0)\n" | |
2376 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
2377 | "VALUES (14,1,'Peer MAC','.1.3.6.1.4.1.45.1.6.13.2.1.1.5',4 ,0)\n" | |
2378 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
2379 | "VALUES (14,2,'Port','.1.3.6.1.4.1.45.1.6.13.2.1.1.2',5 ,0)\n" | |
2380 | "INSERT INTO object_tools_acl (tool_id,user_id) VALUES (14,-2147483648)\n" | |
2381 | "INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description) " | |
2382 | "VALUES (15,'&Info->Topology table (CDP)',2 ,'Topology table',1,'','Show topology table (CDP)')\n" | |
2383 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
2384 | "VALUES (15,0,'Device ID','.1.3.6.1.4.1.9.9.23.1.2.1.1.6',0 ,0)\n" | |
2385 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
2386 | "VALUES (15,1,'IP Address','.1.3.6.1.4.1.9.9.23.1.2.1.1.4',3 ,0)\n" | |
2387 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
2388 | "VALUES (15,2,'Platform','.1.3.6.1.4.1.9.9.23.1.2.1.1.8',0 ,0)\n" | |
2389 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
2390 | "VALUES (15,3,'Version','.1.3.6.1.4.1.9.9.23.1.2.1.1.5',0 ,0)\n" | |
2391 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
2392 | "VALUES (15,4,'Port','.1.3.6.1.4.1.9.9.23.1.2.1.1.7',0 ,0)\n" | |
2393 | "INSERT INTO object_tools_acl (tool_id,user_id) VALUES (15,-2147483648)\n" | |
2394 | "<END>"; | |
2395 | ||
2396 | if (!SQLBatch(m_szBatch)) | |
2397 | if (!g_bIgnoreErrors) | |
2398 | return FALSE; | |
2399 | ||
2400 | if (!SQLQuery(_T("UPDATE config SET var_value='46' WHERE var_name='DBFormatVersion'"))) | |
2401 | if (!g_bIgnoreErrors) | |
2402 | return FALSE; | |
2403 | ||
2404 | return TRUE; | |
2405 | } | |
2406 | ||
2407 | ||
2408 | // | |
2409 | // Upgrade from V44 to V45 | |
2410 | // | |
2411 | ||
31cc1924 | 2412 | static BOOL H_UpgradeFromV44(int currVersion, int newVersion) |
5039dede AK |
2413 | { |
2414 | static TCHAR m_szBatch[] = | |
2415 | "INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) " | |
2416 | "VALUES (36,'SYS_DB_CONN_LOST',4,1," | |
2417 | "'Lost connection with backend database engine'," | |
2418 | "'Generated if connection with backend database engine is lost.#0D#0A" | |
2419 | "Parameters:#0D#0A No message-specific parameters')\n" | |
2420 | "INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) " | |
2421 | "VALUES (37,'SYS_DB_CONN_RESTORED',0,1," | |
2422 | "'Connection with backend database engine restored'," | |
2423 | "'Generated when connection with backend database engine restored.#0D#0A" | |
2424 | "Parameters:#0D#0A No message-specific parameters')\n" | |
2425 | "<END>"; | |
2426 | ||
2427 | if (!SQLBatch(m_szBatch)) | |
2428 | if (!g_bIgnoreErrors) | |
2429 | return FALSE; | |
2430 | ||
2431 | if (!SQLQuery(_T("UPDATE config SET var_value='45' WHERE var_name='DBFormatVersion'"))) | |
2432 | if (!g_bIgnoreErrors) | |
2433 | return FALSE; | |
2434 | ||
2435 | return TRUE; | |
2436 | } | |
2437 | ||
2438 | ||
2439 | // | |
2440 | // Upgrade from V43 to V44 | |
2441 | // | |
2442 | ||
31cc1924 | 2443 | static BOOL H_UpgradeFromV43(int currVersion, int newVersion) |
5039dede AK |
2444 | { |
2445 | static TCHAR m_szBatch[] = | |
2446 | "DELETE FROM object_tools WHERE tool_id=8000\n" | |
2447 | "DELETE FROM object_tools_table_columns WHERE tool_id=8000\n" | |
2448 | "DELETE FROM object_tools_acl WHERE tool_id=8000\n" | |
2449 | "INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags," | |
2450 | "matching_oid,description) VALUES (13,'&Info->&Process list',3," | |
2451 | "'Process List#7FSystem.ProcessList#7F^([0-9]+) (.*)',2,''," | |
2452 | "'Show list of currently running processes')\n" | |
2453 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name," | |
2454 | "col_oid,col_format,col_substr) VALUES (13,0,'PID','',0,1)\n" | |
2455 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name," | |
2456 | "col_oid,col_format,col_substr) VALUES (13,1,'Name','',0,2)\n" | |
2457 | "INSERT INTO object_tools_acl (tool_id,user_id) VALUES (13,-2147483648)\n" | |
2458 | "<END>"; | |
2459 | ||
2460 | if (!CreateTable(_T("CREATE TABLE agent_configs (" | |
2461 | "config_id integer not null," | |
2462 | "config_name varchar(255) not null," | |
2463 | "config_file $SQL:TEXT not null," | |
2464 | "config_filter $SQL:TEXT not null," | |
2465 | "sequence_number integer not null," | |
2466 | "PRIMARY KEY(config_id))"))) | |
2467 | if (!g_bIgnoreErrors) | |
2468 | return FALSE; | |
2469 | ||
2470 | if (!SQLBatch(m_szBatch)) | |
2471 | if (!g_bIgnoreErrors) | |
2472 | return FALSE; | |
2473 | ||
2474 | if (!CreateConfigParam(_T("DBLockPID"), _T("0"), 0, 0)) | |
2475 | if (!g_bIgnoreErrors) | |
2476 | return FALSE; | |
2477 | ||
2478 | if (!SQLQuery(_T("UPDATE config SET var_value='44' WHERE var_name='DBFormatVersion'"))) | |
2479 | if (!g_bIgnoreErrors) | |
2480 | return FALSE; | |
2481 | ||
2482 | return TRUE; | |
2483 | } | |
2484 | ||
2485 | ||
2486 | // | |
2487 | // Upgrade from V42 to V43 | |
2488 | // | |
2489 | ||
31cc1924 | 2490 | static BOOL H_UpgradeFromV42(int currVersion, int newVersion) |
5039dede AK |
2491 | { |
2492 | if (!CreateConfigParam(_T("RADIUSPort"), _T("1645"), 1, 0)) | |
2493 | if (!g_bIgnoreErrors) | |
2494 | return FALSE; | |
2495 | ||
2496 | if (!SQLQuery(_T("UPDATE config SET var_value='43' WHERE var_name='DBFormatVersion'"))) | |
2497 | if (!g_bIgnoreErrors) | |
2498 | return FALSE; | |
2499 | ||
2500 | return TRUE; | |
2501 | } | |
2502 | ||
2503 | ||
2504 | // | |
2505 | // Upgrade from V41 to V42 | |
2506 | // | |
2507 | ||
31cc1924 | 2508 | static BOOL H_UpgradeFromV41(int currVersion, int newVersion) |
5039dede AK |
2509 | { |
2510 | static TCHAR m_szBatch[] = | |
2511 | "INSERT INTO images (image_id,name,file_name_png,file_hash_png," | |
2512 | "file_name_ico,file_hash_ico) VALUES (15,'Obj.Condition'," | |
2513 | "'condition.png','<invalid_hash>','condition.ico','<invalid_hash>')\n" | |
2514 | "INSERT INTO default_images (object_class,image_id) VALUES (13, 15)\n" | |
2515 | "INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) " | |
2516 | "VALUES (1,'.1.3.6.1.4.1.3224.1.*',2,0)\n" | |
2517 | "INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) " | |
2518 | "VALUES (34,'SYS_CONDITION_ACTIVATED',2,1,'Condition \"%2\" activated'," | |
2519 | "'Default event for condition activation.#0D#0AParameters:#0D#0A" | |
2520 | " 1) Condition object ID#0D#0A 2) Condition object name#0D#0A" | |
2521 | " 3) Previous condition status#0D#0A 4) Current condition status')\n" | |
2522 | "INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) " | |
2523 | "VALUES (35,'SYS_CONDITION_DEACTIVATED',0,1,'Condition \"%2\" deactivated'," | |
2524 | "'Default event for condition deactivation.#0D#0AParameters:#0D#0A" | |
2525 | " 1) Condition object ID#0D#0A 2) Condition object name#0D#0A" | |
2526 | " 3) Previous condition status#0D#0A 4) Current condition status')\n" | |
2527 | "<END>"; | |
2528 | ||
2529 | if (!CreateTable(_T("CREATE TABLE conditions (" | |
2530 | "id integer not null," | |
2531 | "activation_event integer not null," | |
2532 | "deactivation_event integer not null," | |
2533 | "source_object integer not null," | |
2534 | "active_status integer not null," | |
2535 | "inactive_status integer not null," | |
2536 | "script $SQL:TEXT not null," | |
2537 | "PRIMARY KEY(id))"))) | |
2538 | if (!g_bIgnoreErrors) | |
2539 | return FALSE; | |
2540 | ||
2541 | if (!CreateTable(_T("CREATE TABLE cond_dci_map (" | |
2542 | "condition_id integer not null," | |
2543 | "dci_id integer not null," | |
2544 | "node_id integer not null," | |
2545 | "dci_func integer not null," | |
2546 | "num_polls integer not null," | |
2547 | "PRIMARY KEY(condition_id,dci_id))"))) | |
2548 | if (!g_bIgnoreErrors) | |
2549 | return FALSE; | |
2550 | ||
2551 | if (!SQLBatch(m_szBatch)) | |
2552 | if (!g_bIgnoreErrors) | |
2553 | return FALSE; | |
2554 | ||
2555 | if (!CreateConfigParam(_T("NumberOfConditionPollers"), _T("10"), 1, 1)) | |
2556 | if (!g_bIgnoreErrors) | |
2557 | return FALSE; | |
2558 | ||
2559 | if (!CreateConfigParam(_T("ConditionPollingInterval"), _T("60"), 1, 1)) | |
2560 | if (!g_bIgnoreErrors) | |
2561 | return FALSE; | |
2562 | ||
2563 | if (!SQLQuery(_T("UPDATE config SET var_value='42' WHERE var_name='DBFormatVersion'"))) | |
2564 | if (!g_bIgnoreErrors) | |
2565 | return FALSE; | |
2566 | ||
2567 | return TRUE; | |
2568 | } | |
2569 | ||
2570 | ||
2571 | // | |
2572 | // Upgrade from V40 to V41 | |
2573 | // | |
2574 | ||
31cc1924 | 2575 | static BOOL H_UpgradeFromV40(int currVersion, int newVersion) |
5039dede AK |
2576 | { |
2577 | static TCHAR m_szBatch[] = | |
2578 | "ALTER TABLE users ADD guid varchar(36)\n" | |
2579 | "ALTER TABLE users ADD auth_method integer\n" | |
2580 | "ALTER TABLE user_groups ADD guid varchar(36)\n" | |
2581 | "UPDATE users SET auth_method=0\n" | |
2582 | "<END>"; | |
2583 | DB_RESULT hResult; | |
2584 | int i, nCount; | |
2585 | DWORD dwId; | |
2586 | uuid_t guid; | |
2587 | TCHAR szQuery[256], szGUID[64]; | |
2588 | ||
2589 | if (!SQLBatch(m_szBatch)) | |
2590 | if (!g_bIgnoreErrors) | |
2591 | return FALSE; | |
2592 | ||
2593 | // Generate GUIDs for users and groups | |
2594 | printf("Generating GUIDs...\n"); | |
2595 | ||
2596 | hResult = SQLSelect(_T("SELECT id FROM users")); | |
2597 | if (hResult != NULL) | |
2598 | { | |
2599 | nCount = DBGetNumRows(hResult); | |
2600 | for(i = 0; i < nCount; i++) | |
2601 | { | |
2602 | dwId = DBGetFieldULong(hResult, i, 0); | |
2603 | uuid_generate(guid); | |
2604 | _sntprintf(szQuery, 256, _T("UPDATE users SET guid='%s' WHERE id=%d"), | |
2605 | uuid_to_string(guid, szGUID), dwId); | |
2606 | if (!SQLQuery(szQuery)) | |
2607 | if (!g_bIgnoreErrors) | |
2608 | { | |
2609 | DBFreeResult(hResult); | |
2610 | return FALSE; | |
2611 | } | |
2612 | } | |
2613 | DBFreeResult(hResult); | |
2614 | } | |
2615 | ||
2616 | hResult = SQLSelect(_T("SELECT id FROM user_groups")); | |
2617 | if (hResult != NULL) | |
2618 | { | |
2619 | nCount = DBGetNumRows(hResult); | |
2620 | for(i = 0; i < nCount; i++) | |
2621 | { | |
2622 | dwId = DBGetFieldULong(hResult, i, 0); | |
2623 | uuid_generate(guid); | |
2624 | _sntprintf(szQuery, 256, _T("UPDATE user_groups SET guid='%s' WHERE id=%d"), | |
2625 | uuid_to_string(guid, szGUID), dwId); | |
2626 | if (!SQLQuery(szQuery)) | |
2627 | if (!g_bIgnoreErrors) | |
2628 | { | |
2629 | DBFreeResult(hResult); | |
2630 | return FALSE; | |
2631 | } | |
2632 | } | |
2633 | DBFreeResult(hResult); | |
2634 | } | |
2635 | ||
2636 | if (!CreateConfigParam(_T("RADIUSServer"), _T("localhost"), 1, 0)) | |
2637 | if (!g_bIgnoreErrors) | |
2638 | return FALSE; | |
2639 | ||
2640 | if (!CreateConfigParam(_T("RADIUSSecret"), _T("netxms"), 1, 0)) | |
2641 | if (!g_bIgnoreErrors) | |
2642 | return FALSE; | |
2643 | ||
2644 | if (!CreateConfigParam(_T("RADIUSNumRetries"), _T("5"), 1, 0)) | |
2645 | if (!g_bIgnoreErrors) | |
2646 | return FALSE; | |
2647 | ||
2648 | if (!CreateConfigParam(_T("RADIUSTimeout"), _T("3"), 1, 0)) | |
2649 | if (!g_bIgnoreErrors) | |
2650 | return FALSE; | |
2651 | ||
2652 | if (!SQLQuery(_T("UPDATE config SET var_value='41' WHERE var_name='DBFormatVersion'"))) | |
2653 | if (!g_bIgnoreErrors) | |
2654 | return FALSE; | |
2655 | ||
2656 | return TRUE; | |
2657 | } | |
2658 | ||
2659 | ||
2660 | // | |
2661 | // Upgrade from V39 to V40 | |
2662 | // | |
2663 | ||
31cc1924 | 2664 | static BOOL H_UpgradeFromV39(int currVersion, int newVersion) |
5039dede AK |
2665 | { |
2666 | static TCHAR m_szBatch[] = | |
2667 | "ALTER TABLE users ADD grace_logins integer\n" | |
2668 | "UPDATE users SET grace_logins=5\n" | |
2669 | "<END>"; | |
2670 | ||
2671 | if (!SQLBatch(m_szBatch)) | |
2672 | if (!g_bIgnoreErrors) | |
2673 | return FALSE; | |
2674 | ||
2675 | if (!SQLQuery(_T("UPDATE config SET var_value='40' WHERE var_name='DBFormatVersion'"))) | |
2676 | if (!g_bIgnoreErrors) | |
2677 | return FALSE; | |
2678 | ||
2679 | return TRUE; | |
2680 | } | |
2681 | ||
2682 | ||
2683 | // | |
2684 | // Upgrade from V38 to V39 | |
2685 | // | |
2686 | ||
31cc1924 | 2687 | static BOOL H_UpgradeFromV38(int currVersion, int newVersion) |
5039dede AK |
2688 | { |
2689 | static TCHAR m_szBatch[] = | |
2690 | "INSERT INTO maps (map_id,map_name,description,root_object_id) " | |
2691 | "VALUES (1,'Default','Default network map',1)\n" | |
2692 | "INSERT INTO map_access_lists (map_id,user_id,access_rights) VALUES (1,-2147483648,1)\n" | |
2693 | "INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) " | |
2694 | "VALUES (33,'SYS_SCRIPT_ERROR',2,1," | |
2695 | "'Script (%1) execution error: %2'," | |
2696 | "'Generated when server encounters NXSL script execution error.#0D#0A" | |
2697 | "Parameters:#0D#0A" | |
2698 | " 1) Script name#0D#0A" | |
2699 | " 2) Error text#0D#0A" | |
2700 | " 3) DCI ID if script is DCI transformation script, or 0 otherwise')\n" | |
2701 | "<END>"; | |
2702 | ||
2703 | if (!CreateTable(_T("CREATE TABLE maps (" | |
2704 | "map_id integer not null," | |
2705 | "map_name varchar(255) not null," | |
2706 | "description $SQL:TEXT not null," | |
2707 | "root_object_id integer not null," | |
2708 | "PRIMARY KEY(map_id))"))) | |
2709 | if (!g_bIgnoreErrors) | |
2710 | return FALSE; | |
2711 | ||
2712 | if (!CreateTable(_T("CREATE TABLE map_access_lists (" | |
2713 | "map_id integer not null," | |
2714 | "user_id integer not null," | |
2715 | "access_rights integer not null," | |
2716 | "PRIMARY KEY(map_id,user_id))"))) | |
2717 | if (!g_bIgnoreErrors) | |
2718 | return FALSE; | |
2719 | ||
2720 | if (!CreateTable(_T("CREATE TABLE submaps (" | |
2721 | "map_id integer not null," | |
2722 | "submap_id integer not null," | |
2723 | "attributes integer not null," | |
2724 | "PRIMARY KEY(map_id,submap_id))"))) | |
2725 | if (!g_bIgnoreErrors) | |
2726 | return FALSE; | |
2727 | ||
2728 | if (!CreateTable(_T("CREATE TABLE submap_object_positions (" | |
2729 | "map_id integer not null," | |
2730 | "submap_id integer not null," | |
2731 | "object_id integer not null," | |
2732 | "x integer not null," | |
2733 | "y integer not null," | |
2734 | "PRIMARY KEY(map_id,submap_id,object_id))"))) | |
2735 | if (!g_bIgnoreErrors) | |
2736 | return FALSE; | |
2737 | ||
2738 | if (!CreateTable(_T("CREATE TABLE submap_links (" | |
2739 | "map_id integer not null," | |
2740 | "submap_id integer not null," | |
2741 | "object_id1 integer not null," | |
2742 | "object_id2 integer not null," | |
2743 | "link_type integer not null," | |
2744 | "PRIMARY KEY(map_id,submap_id,object_id1,object_id2))"))) | |
2745 | if (!g_bIgnoreErrors) | |
2746 | return FALSE; | |
2747 | ||
2748 | if (!SQLBatch(m_szBatch)) | |
2749 | if (!g_bIgnoreErrors) | |
2750 | return FALSE; | |
2751 | ||
2752 | if (!CreateConfigParam(_T("LockTimeout"), _T("60000"), 1, 1)) | |
2753 | if (!g_bIgnoreErrors) | |
2754 | return FALSE; | |
2755 | ||
2756 | if (!CreateConfigParam(_T("DisableVacuum"), _T("0"), 1, 0)) | |
2757 | if (!g_bIgnoreErrors) | |
2758 | return FALSE; | |
2759 | ||
2760 | if (!SQLQuery(_T("UPDATE config SET var_value='39' WHERE var_name='DBFormatVersion'"))) | |
2761 | if (!g_bIgnoreErrors) | |
2762 | return FALSE; | |
2763 | ||
2764 | return TRUE; | |
2765 | } | |
2766 | ||
2767 | ||
2768 | // | |
2769 | // Upgrade from V37 to V38 | |
2770 | // | |
2771 | ||
31cc1924 | 2772 | static BOOL H_UpgradeFromV37(int currVersion, int newVersion) |
5039dede AK |
2773 | { |
2774 | static TCHAR m_szBatch[] = | |
2775 | "CREATE INDEX idx_event_log_event_timestamp ON event_log(event_timestamp)\n" | |
2776 | "CREATE INDEX idx_syslog_msg_timestamp ON syslog(msg_timestamp)\n" | |
2777 | "CREATE INDEX idx_snmp_trap_log_trap_timestamp ON snmp_trap_log(trap_timestamp)\n" | |
2778 | "<END>"; | |
2779 | ||
2780 | if (!CreateTable(_T("CREATE TABLE snmp_trap_log (" | |
2781 | "trap_id $SQL:INT64 not null," | |
2782 | "trap_timestamp integer not null," | |
2783 | "ip_addr varchar(15) not null," | |
2784 | "object_id integer not null," | |
2785 | "trap_oid varchar(255) not null," | |
2786 | "trap_varlist $SQL:TEXT not null," | |
2787 | "PRIMARY KEY(trap_id))"))) | |
2788 | ||
2789 | if (!g_bIgnoreErrors) | |
2790 | return FALSE; | |
2791 | ||
2792 | if (!SQLBatch(m_szBatch)) | |
2793 | if (!g_bIgnoreErrors) | |
2794 | return FALSE; | |
2795 | ||
2796 | if (!CreateConfigParam(_T("LogAllSNMPTraps"), _T("0"), 1, 1)) | |
2797 | if (!g_bIgnoreErrors) | |
2798 | return FALSE; | |
2799 | ||
2800 | if (!SQLQuery(_T("UPDATE config SET var_value='38' WHERE var_name='DBFormatVersion'"))) | |
2801 | if (!g_bIgnoreErrors) | |
2802 | return FALSE; | |
2803 | ||
2804 | return TRUE; | |
2805 | } | |
2806 | ||
2807 | ||
2808 | // | |
2809 | // Upgrade from V36 to V37 | |
2810 | // | |
2811 | ||
31cc1924 | 2812 | static BOOL H_UpgradeFromV36(int currVersion, int newVersion) |
5039dede AK |
2813 | { |
2814 | static TCHAR m_szBatch[] = | |
2815 | "DROP TABLE new_nodes\n" | |
2816 | "DELETE FROM config WHERE var_name='NewNodePollingInterval'\n" | |
2817 | "INSERT INTO script_library (script_id,script_name,script_code) " | |
2818 | "VALUES (1,'Filter::SNMP','sub main()#0D#0A{#0D#0A return $1->isSNMP;#0D#0A}#0D#0A')\n" | |
2819 | "INSERT INTO script_library (script_id,script_name,script_code) " | |
2820 | "VALUES (2,'Filter::Agent','sub main()#0D#0A{#0D#0A return $1->isAgent;#0D#0A}#0D#0A')\n" | |
2821 | "INSERT INTO script_library (script_id,script_name,script_code) " | |
2822 | "VALUES (3,'Filter::AgentOrSNMP','sub main()#0D#0A{#0D#0A return $1->isAgent || $1->isSNMP;#0D#0A}#0D#0A')\n" | |
2823 | "INSERT INTO script_library (script_id,script_name,script_code) " | |
2824 | "VALUES (4,'DCI::SampleTransform','sub dci_transform()#0D#0A{#0D#0A return $1 + 1;#0D#0A}#0D#0A')\n" | |
2825 | "<END>"; | |
2826 | ||
2827 | if (!CreateTable(_T("CREATE TABLE script_library (" | |
2828 | "script_id integer not null," | |
2829 | "script_name varchar(63) not null," | |
2830 | "script_code $SQL:TEXT not null," | |
2831 | "PRIMARY KEY(script_id))"))) | |
2832 | if (!g_bIgnoreErrors) | |
2833 | return FALSE; | |
2834 | ||
2835 | if (!SQLBatch(m_szBatch)) | |
2836 | if (!g_bIgnoreErrors) | |
2837 | return FALSE; | |
2838 | ||
2839 | if (!CreateConfigParam(_T("DefaultCommunityString"), _T("public"), 1, 0)) | |
2840 | if (!g_bIgnoreErrors) | |
2841 | return FALSE; | |
2842 | ||
2843 | if (!CreateConfigParam(_T("DiscoveryFilter"), _T("none"), 1, 0)) | |
2844 | if (!g_bIgnoreErrors) | |
2845 | return FALSE; | |
2846 | ||
2847 | if (!SQLQuery(_T("UPDATE config SET var_value='37' WHERE var_name='DBFormatVersion'"))) | |
2848 | if (!g_bIgnoreErrors) | |
2849 | return FALSE; | |
2850 | ||
2851 | return TRUE; | |
2852 | } | |
2853 | ||
2854 | ||
2855 | // | |
2856 | // Upgrade from V35 to V36 | |
2857 | // | |
2858 | ||
31cc1924 | 2859 | static BOOL H_UpgradeFromV35(int currVersion, int newVersion) |
5039dede AK |
2860 | { |
2861 | static TCHAR m_szBatch[] = | |
2862 | "ALTER TABLE nodes ADD proxy_node integer\n" | |
2863 | "UPDATE nodes SET proxy_node=0\n" | |
2864 | "ALTER TABLE object_tools ADD matching_oid varchar(255)\n" | |
2865 | "UPDATE object_tools SET matching_oid='#00'\n" | |
2866 | "<END>"; | |
2867 | ||
2868 | if (!SQLBatch(m_szBatch)) | |
2869 | if (!g_bIgnoreErrors) | |
2870 | return FALSE; | |
2871 | ||
2872 | if (!CreateConfigParam(_T("CapabilityExpirationTime"), _T("604800"), 1, 0)) | |
2873 | if (!g_bIgnoreErrors) | |
2874 | return FALSE; | |
2875 | ||
2876 | if (!SQLQuery(_T("UPDATE config SET var_value='36' WHERE var_name='DBFormatVersion'"))) | |
2877 | if (!g_bIgnoreErrors) | |
2878 | return FALSE; | |
2879 | ||
2880 | return TRUE; | |
2881 | } | |
2882 | ||
2883 | ||
2884 | // | |
2885 | // Upgrade from V34 to V35 | |
2886 | // | |
2887 | ||
31cc1924 | 2888 | static BOOL H_UpgradeFromV34(int currVersion, int newVersion) |
5039dede AK |
2889 | { |
2890 | static TCHAR m_szBatch[] = | |
2891 | "ALTER TABLE object_properties DROP COLUMN status_alg\n" | |
2892 | "ALTER TABLE object_properties ADD status_calc_alg integer\n" | |
2893 | "ALTER TABLE object_properties ADD status_prop_alg integer\n" | |
2894 | "ALTER TABLE object_properties ADD status_fixed_val integer\n" | |
2895 | "ALTER TABLE object_properties ADD status_shift integer\n" | |
2896 | "ALTER TABLE object_properties ADD status_translation varchar(8)\n" | |
2897 | "ALTER TABLE object_properties ADD status_single_threshold integer\n" | |
2898 | "ALTER TABLE object_properties ADD status_thresholds varchar(8)\n" | |
2899 | "UPDATE object_properties SET status_calc_alg=0,status_prop_alg=0," | |
2900 | "status_fixed_val=0,status_shift=0,status_translation='01020304'," | |
2901 | "status_single_threshold=75,status_thresholds='503C2814'\n" | |
2902 | "DELETE FROM config WHERE var_name='StatusCalculationAlgorithm'\n" | |
2903 | "<END>"; | |
2904 | ||
2905 | if (!SQLBatch(m_szBatch)) | |
2906 | if (!g_bIgnoreErrors) | |
2907 | return FALSE; | |
2908 | ||
2909 | if (!CreateConfigParam(_T("StatusCalculationAlgorithm"), _T("1"), 1, 1)) | |
2910 | if (!g_bIgnoreErrors) | |
2911 | return FALSE; | |
2912 | ||
2913 | if (!CreateConfigParam(_T("StatusPropagationAlgorithm"), _T("1"), 1, 1)) | |
2914 | if (!g_bIgnoreErrors) | |
2915 | return FALSE; | |
2916 | ||
2917 | if (!CreateConfigParam(_T("FixedStatusValue"), _T("0"), 1, 1)) | |
2918 | if (!g_bIgnoreErrors) | |
2919 | return FALSE; | |
2920 | ||
2921 | if (!CreateConfigParam(_T("StatusShift"), _T("0"), 1, 1)) | |
2922 | if (!g_bIgnoreErrors) | |
2923 | return FALSE; | |
2924 | ||
2925 | if (!CreateConfigParam(_T("StatusTranslation"), _T("01020304"), 1, 1)) | |
2926 | if (!g_bIgnoreErrors) | |
2927 | return FALSE; | |
2928 | ||
2929 | if (!CreateConfigParam(_T("StatusSingleThreshold"), _T("75"), 1, 1)) | |
2930 | if (!g_bIgnoreErrors) | |
2931 | return FALSE; | |
2932 | ||
2933 | if (!CreateConfigParam(_T("StatusThresholds"), _T("503C2814"), 1, 1)) | |
2934 | if (!g_bIgnoreErrors) | |
2935 | return FALSE; | |
2936 | ||
2937 | if (!SQLQuery(_T("UPDATE config SET var_value='35' WHERE var_name='DBFormatVersion'"))) | |
2938 | if (!g_bIgnoreErrors) | |
2939 | return FALSE; | |
2940 | ||
2941 | return TRUE; | |
2942 | } | |
2943 | ||
2944 | ||
2945 | // | |
2946 | // Upgrade from V33 to V34 | |
2947 | // | |
2948 | ||
31cc1924 | 2949 | static BOOL H_UpgradeFromV33(int currVersion, int newVersion) |
5039dede AK |
2950 | { |
2951 | static TCHAR m_szBatch[] = | |
2952 | "ALTER TABLE items ADD adv_schedule integer\n" | |
2953 | "UPDATE items SET adv_schedule=0\n" | |
2954 | "<END>"; | |
2955 | ||
2956 | if (!SQLBatch(m_szBatch)) | |
2957 | if (!g_bIgnoreErrors) | |
2958 | return FALSE; | |
2959 | ||
2960 | if (!CreateTable(_T("CREATE TABLE dci_schedules (" | |
2961 | "item_id integer not null," | |
2962 | "schedule varchar(255) not null)"))) | |
2963 | if (!g_bIgnoreErrors) | |
2964 | return FALSE; | |
2965 | ||
2966 | if (!CreateTable(_T("CREATE TABLE syslog (" | |
2967 | "msg_id $SQL:INT64 not null," | |
2968 | "msg_timestamp integer not null," | |
2969 | "facility integer not null," | |
2970 | "severity integer not null," | |
2971 | "source_object_id integer not null," | |
2972 | "hostname varchar(127) not null," | |
2973 | "msg_tag varchar(32) not null," | |
2974 | "msg_text $SQL:TEXT not null," | |
2975 | "PRIMARY KEY(msg_id))"))) | |
2976 | if (!g_bIgnoreErrors) | |
2977 | return FALSE; | |
2978 | ||
2979 | if (!CreateConfigParam(_T("IcmpPingSize"), _T("46"), 1, 1)) | |
2980 | if (!g_bIgnoreErrors) | |
2981 | return FALSE; | |
2982 | ||
2983 | if (!CreateConfigParam(_T("SMSDrvConfig"), _T(""), 1, 1)) | |
2984 | if (!g_bIgnoreErrors) | |
2985 | return FALSE; | |
2986 | ||
2987 | if (!CreateConfigParam(_T("EnableSyslogDaemon"), _T("0"), 1, 1)) | |
2988 | if (!g_bIgnoreErrors) | |
2989 | return FALSE; | |
2990 | ||
2991 | if (!CreateConfigParam(_T("SyslogListenPort"), _T("514"), 1, 1)) | |
2992 | if (!g_bIgnoreErrors) | |
2993 | return FALSE; | |
2994 | ||
2995 | if (!CreateConfigParam(_T("SyslogRetentionTime"), _T("5184000"), 1, 0)) | |
2996 | if (!g_bIgnoreErrors) | |
2997 | return FALSE; | |
2998 | ||
2999 | if (!SQLQuery(_T("UPDATE config SET var_value='34' WHERE var_name='DBFormatVersion'"))) | |
3000 | if (!g_bIgnoreErrors) | |
3001 | return FALSE; | |
3002 | ||
3003 | return TRUE; | |
3004 | } | |
3005 | ||
3006 | ||
3007 | // | |
3008 | // Upgrade from V32 to V33 | |
3009 | // | |
3010 | ||
31cc1924 | 3011 | static BOOL H_UpgradeFromV32(int currVersion, int newVersion) |
5039dede AK |
3012 | { |
3013 | static TCHAR m_szBatch[] = | |
3014 | "INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,description) " | |
3015 | "VALUES (5,'&Info->&Switch forwarding database (FDB)',2 ,'Forwarding database',0,'Show switch forwarding database')\n" | |
3016 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
3017 | "VALUES (5,0,'MAC Address','.1.3.6.1.2.1.17.4.3.1.1',4 ,0)\n" | |
3018 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
3019 | "VALUES (5,1,'Port','.1.3.6.1.2.1.17.4.3.1.2',1 ,0)\n" | |
3020 | "INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,description) " | |
3021 | "VALUES (6,'&Connect->Open &web browser',4 ,'http://%OBJECT_IP_ADDR%',0,'Open embedded web browser to node')\n" | |
3022 | "INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,description) " | |
3023 | "VALUES (7,'&Connect->Open &web browser (HTTPS)',4 ,'https://%OBJECT_IP_ADDR%',0,'Open embedded web browser to node using HTTPS')\n" | |
3024 | "INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,description) " | |
3025 | "VALUES (8,'&Info->&Agent->&Subagent list',3 ,'Subagent List#7FAgent.SubAgentList#7F^(.*) (.*) (.*) (.*)',0,'Show list of loaded subagents')\n" | |
3026 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
3027 | "VALUES (8,0,'Name','',0 ,1)\n" | |
3028 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
3029 | "VALUES (8,1,'Version','',0 ,2)\n" | |
3030 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
3031 | "VALUES (8,2,'File','',0 ,4)\n" | |
3032 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
3033 | "VALUES (8,3,'Module handle','',0 ,3)\n" | |
3034 | "INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,description) " | |
3035 | "VALUES (9,'&Info->&Agent->Supported ¶meters',3 ,'Supported parameters#7FAgent.SupportedParameters#7F^(.*)',0,'Show list of parameters supported by agent')\n" | |
3036 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
3037 | "VALUES (9,0,'Parameter','',0 ,1)\n" | |
3038 | "INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,description) " | |
3039 | "VALUES (10,'&Info->&Agent->Supported &enums',3 ,'Supported enums#7FAgent.SupportedEnums#7F^(.*)',0,'Show list of enums supported by agent')\n" | |
3040 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
3041 | "VALUES (10,0,'Parameter','',0 ,1)\n" | |
3042 | "INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,description) " | |
3043 | "VALUES (11,'&Info->&Agent->Supported &actions',3 ,'Supported actions#7FAgent.ActionList#7F^(.*) (.*) #22(.*)#22.*',0,'Show list of actions supported by agent')\n" | |
3044 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
3045 | "VALUES (11,0,'Name','',0 ,1)\n" | |
3046 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
3047 | "VALUES (11,1,'Type','',0 ,2)\n" | |
3048 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
3049 | "VALUES (11,2,'Data','',0 ,3)\n" | |
3050 | "INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,description) " | |
3051 | "VALUES (12,'&Info->&Agent->Configured &ICMP targets',3 ,'Configured ICMP targets#7FICMP.TargetList#7F^(.*) (.*) (.*) (.*)',0,'Show list of actions supported by agent')\n" | |
3052 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
3053 | "VALUES (12,0,'IP Address','',0 ,1)\n" | |
3054 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
3055 | "VALUES (12,1,'Name','',0 ,4)\n" | |
3056 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
3057 | "VALUES (12,2,'Last RTT','',0 ,2)\n" | |
3058 | "INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) " | |
3059 | "VALUES (12,4,'Average RTT','',0 ,3)\n" | |
3060 | "INSERT INTO object_tools_acl (tool_id,user_id) VALUES (5,-2147483648)\n" | |
3061 | "INSERT INTO object_tools_acl (tool_id,user_id) VALUES (6,-2147483648)\n" | |
3062 | "INSERT INTO object_tools_acl (tool_id,user_id) VALUES (7,-2147483648)\n" | |
3063 | "INSERT INTO object_tools_acl (tool_id,user_id) VALUES (8,-2147483648)\n" | |
3064 | "INSERT INTO object_tools_acl (tool_id,user_id) VALUES (9,-2147483648)\n" | |
3065 | "INSERT INTO object_tools_acl (tool_id,user_id) VALUES (10,-2147483648)\n" | |
3066 | "INSERT INTO object_tools_acl (tool_id,user_id) VALUES (11,-2147483648)\n" | |
3067 | "INSERT INTO object_tools_acl (tool_id,user_id) VALUES (12,-2147483648)\n" | |
3068 | "<END>"; | |
3069 | ||
3070 | if (!CreateTable(_T("CREATE TABLE object_tools_table_columns (" | |
3071 | "tool_id integer not null," | |
3072 | "col_number integer not null," | |
3073 | "col_name varchar(255)," | |
3074 | "col_oid varchar(255)," | |
3075 | "col_format integer," | |
3076 | "col_substr integer," | |
3077 | "PRIMARY KEY(tool_id,col_number))"))) | |
3078 | if (!g_bIgnoreErrors) | |
3079 | return FALSE; | |
3080 | ||
3081 | if (!SQLBatch(m_szBatch)) | |
3082 | if (!g_bIgnoreErrors) | |
3083 | return FALSE; | |
3084 | ||
3085 | if (!SQLQuery(_T("UPDATE config SET var_value='33' WHERE var_name='DBFormatVersion'"))) | |
3086 | if (!g_bIgnoreErrors) | |
3087 | return FALSE; | |
3088 | ||
3089 | return TRUE; | |
3090 | } | |
3091 | ||
3092 | ||
3093 | // | |
3094 | // Upgrade from V31 to V32 | |
3095 | // | |
3096 | ||
31cc1924 | 3097 | static BOOL H_UpgradeFromV31(int currVersion, int newVersion) |
5039dede AK |
3098 | { |
3099 | static TCHAR m_szBatch[] = | |
3100 | "INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,description) " | |
3101 | "VALUES (1,'&Shutdown system',1 ,'System.Shutdown',0,'Shutdown target node via NetXMS agent')\n" | |
3102 | "INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,description) " | |
3103 | "VALUES (2,'&Restart system',1 ,'System.Restart',0,'Restart target node via NetXMS agent')\n" | |
3104 | "INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,description) " | |
3105 | "VALUES (3,'&Wakeup node',0 ,'wakeup',0,'Wakeup node using Wake-On-LAN magic packet')\n" | |
3106 | "INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,description) " | |
3107 | "VALUES (4,'Restart &agent',1 ,'Agent.Restart',0,'Restart NetXMS agent on target node')\n" | |
3108 | "INSERT INTO object_tools_acl (tool_id,user_id) VALUES (1,-2147483648)\n" | |
3109 | "INSERT INTO object_tools_acl (tool_id,user_id) VALUES (2,-2147483648)\n" | |
3110 | "INSERT INTO object_tools_acl (tool_id,user_id) VALUES (3,-2147483648)\n" | |
3111 | "INSERT INTO object_tools_acl (tool_id,user_id) VALUES (4,-2147483648)\n" | |
3112 | "<END>"; | |
3113 | ||
3114 | if (!CreateTable(_T("CREATE TABLE object_tools (" | |
3115 | "tool_id integer not null," | |
3116 | "tool_name varchar(255) not null," | |
3117 | "tool_type integer not null," | |
3118 | "tool_data $SQL:TEXT," | |
3119 | "description varchar(255)," | |
3120 | "flags integer not null," | |
3121 | "PRIMARY KEY(tool_id))"))) | |
3122 | if (!g_bIgnoreErrors) | |
3123 | return FALSE; | |
3124 | ||
3125 | if (!CreateTable(_T("CREATE TABLE object_tools_acl (" | |
3126 | "tool_id integer not null," | |
3127 | "user_id integer not null," | |
3128 | "PRIMARY KEY(tool_id,user_id))"))) | |
3129 | if (!g_bIgnoreErrors) | |
3130 | return FALSE; | |
3131 | ||
3132 | if (!SQLBatch(m_szBatch)) | |
3133 | if (!g_bIgnoreErrors) | |
3134 | return FALSE; | |
3135 | ||
3136 | if (!SQLQuery(_T("UPDATE config SET var_value='32' WHERE var_name='DBFormatVersion'"))) | |
3137 | if (!g_bIgnoreErrors) | |
3138 | return FALSE; | |
3139 | ||
3140 | return TRUE; | |
3141 | } | |
3142 | ||
3143 | ||
3144 | // | |
3145 | // Upgrade from V30 to V31 | |
3146 | // | |
3147 | ||
31cc1924 | 3148 | static BOOL H_UpgradeFromV30(int currVersion, int newVersion) |
5039dede AK |
3149 | { |
3150 | static TCHAR m_szBatch[] = | |
3151 | "INSERT INTO default_images (object_class,image_id) " | |
3152 | "VALUES (12, 14)\n" | |
3153 | "INSERT INTO images (image_id,name,file_name_png,file_hash_png," | |
3154 | "file_name_ico,file_hash_ico) VALUES (14,'Obj.VPNConnector'," | |
3155 | "'vpnc.png','<invalid_hash>','vpnc.ico','<invalid_hash>')\n" | |
3156 | "<END>"; | |
3157 | ||
3158 | if (!SQLBatch(m_szBatch)) | |
3159 | if (!g_bIgnoreErrors) | |
3160 | return FALSE; | |
3161 | ||
3162 | if (!CreateTable(_T("CREATE TABLE vpn_connectors (" | |
3163 | "id integer not null," | |
3164 | "node_id integer not null," | |
3165 | "peer_gateway integer not null," | |
3166 | "PRIMARY KEY(id))"))) | |
3167 | if (!g_bIgnoreErrors) | |
3168 | return FALSE; | |
3169 | ||
3170 | if (!CreateTable(_T("CREATE TABLE vpn_connector_networks (" | |
3171 | "vpn_id integer not null," | |
3172 | "network_type integer not null," | |
3173 | "ip_addr varchar(15) not null," | |
3174 | "ip_netmask varchar(15) not null," | |
3175 | "PRIMARY KEY(vpn_id,ip_addr))"))) | |
3176 | if (!g_bIgnoreErrors) | |
3177 | return FALSE; | |
3178 | ||
3179 | if (!CreateConfigParam(_T("NumberOfRoutingTablePollers"), _T("5"), 1, 1)) | |
3180 | if (!g_bIgnoreErrors) | |
3181 | return FALSE; | |
3182 | ||
3183 | if (!CreateConfigParam(_T("RoutingTableUpdateInterval"), _T("300"), 1, 1)) | |
3184 | if (!g_bIgnoreErrors) | |
3185 | return FALSE; | |
3186 | ||
3187 | if (!SQLQuery(_T("UPDATE config SET var_value='31' WHERE var_name='DBFormatVersion'"))) | |
3188 | if (!g_bIgnoreErrors) | |
3189 | return FALSE; | |
3190 | ||
3191 | return TRUE; | |
3192 | } | |
3193 | ||
3194 | ||
3195 | // | |
3196 | // Upgrade from V29 to V30 | |
3197 | // | |
3198 | ||
31cc1924 | 3199 | static BOOL H_UpgradeFromV29(int currVersion, int newVersion) |
5039dede AK |
3200 | { |
3201 | static TCHAR m_szBatch[] = | |
3202 | "ALTER TABLE object_properties ADD status_alg integer\n" | |
3203 | "UPDATE object_properties SET status_alg=-1\n" | |
3204 | "<END>"; | |
3205 | ||
3206 | if (!SQLBatch(m_szBatch)) | |
3207 | if (!g_bIgnoreErrors) | |
3208 | return FALSE; | |
3209 | ||
3210 | if (!CreateConfigParam(_T("StatusCalculationAlgorithm"), _T("0"), 1, 1)) | |
3211 | if (!g_bIgnoreErrors) | |
3212 | return FALSE; | |
3213 | ||
3214 | if (!CreateConfigParam(_T("EnableMultipleDBConnections"), _T("1"), 1, 1)) | |
3215 | if (!g_bIgnoreErrors) | |
3216 | return FALSE; | |
3217 | ||
3218 | if (!CreateConfigParam(_T("NumberOfDatabaseWriters"), _T("1"), 1, 1)) | |
3219 | if (!g_bIgnoreErrors) | |
3220 | return FALSE; | |
3221 | ||
3222 | if (!CreateConfigParam(_T("DefaultEncryptionPolicy"), _T("1"), 1, 1)) | |
3223 | if (!g_bIgnoreErrors) | |
3224 | return FALSE; | |
3225 | ||
3226 | if (!CreateConfigParam(_T("AllowedCiphers"), _T("15"), 1, 1)) | |
3227 | if (!g_bIgnoreErrors) | |
3228 | return FALSE; | |
3229 | ||
3230 | if (!CreateConfigParam(_T("KeepAliveInterval"), _T("60"), 1, 1)) | |
3231 | if (!g_bIgnoreErrors) | |
3232 | return FALSE; | |
3233 | ||
3234 | if (!SQLQuery(_T("UPDATE config SET var_value='30' WHERE var_name='DBFormatVersion'"))) | |
3235 | if (!g_bIgnoreErrors) | |
3236 | return FALSE; | |
3237 | ||
3238 | return TRUE; | |
3239 | } | |
3240 | ||
3241 | ||
3242 | // | |
3243 | // Upgrade from V28 to V29 | |
3244 | // | |
3245 | ||
31cc1924 | 3246 | static BOOL H_UpgradeFromV28(int currVersion, int newVersion) |
5039dede AK |
3247 | { |
3248 | static TCHAR m_szBatch[] = | |
3249 | "ALTER TABLE nodes ADD zone_guid integer\n" | |
3250 | "ALTER TABLE subnets ADD zone_guid integer\n" | |
3251 | "UPDATE nodes SET zone_guid=0\n" | |
3252 | "UPDATE subnets SET zone_guid=0\n" | |
3253 | "INSERT INTO default_images (object_class,image_id) VALUES (6,13)\n" | |
3254 | "INSERT INTO images (image_id,name,file_name_png,file_hash_png," | |
3255 | "file_name_ico,file_hash_ico) VALUES (13,'Obj.Zone','zone.png'," | |
3256 | "'<invalid_hash>','zone.ico','<invalid_hash>')\n" | |
3257 | "<END>"; | |
3258 | ||
3259 | if (!CreateTable(_T("CREATE TABLE zones (" | |
3260 | "id integer not null," | |
3261 | "zone_guid integer not null," | |
3262 | "zone_type integer not null," | |
3263 | "controller_ip varchar(15) not null," | |
3264 | "description $SQL:TEXT," | |
3265 | "PRIMARY KEY(id))"))) | |
3266 | if (!g_bIgnoreErrors) | |
3267 | return FALSE; | |
3268 | ||
3269 | if (!CreateTable(_T("CREATE TABLE zone_ip_addr_list (" | |
3270 | "zone_id integer not null," | |
3271 | "ip_addr varchar(15) not null," | |
3272 | "PRIMARY KEY(zone_id,ip_addr))"))) | |
3273 | if (!g_bIgnoreErrors) | |
3274 | return FALSE; | |
3275 | ||
3276 | if (!SQLBatch(m_szBatch)) | |
3277 | if (!g_bIgnoreErrors) | |
3278 | return FALSE; | |
3279 | ||
3280 | if (!CreateConfigParam(_T("EnableZoning"), _T("0"), 1, 1)) | |
3281 | if (!g_bIgnoreErrors) | |
3282 | return FALSE; | |
3283 | ||
3284 | if (!SQLQuery(_T("UPDATE config SET var_value='29' WHERE var_name='DBFormatVersion'"))) | |
3285 | if (!g_bIgnoreErrors) | |
3286 | return FALSE; | |
3287 | ||
3288 | return TRUE; | |
3289 | } | |
3290 | ||
3291 | ||
3292 | // | |
3293 | // Upgrade from V27 to V28 | |
3294 | // | |
3295 | ||
31cc1924 | 3296 | static BOOL H_UpgradeFromV27(int currVersion, int newVersion) |
5039dede AK |
3297 | { |
3298 | static TCHAR m_szBatch[] = | |
3299 | "ALTER TABLE users ADD system_access integer\n" | |
3300 | "UPDATE users SET system_access=access\n" | |
3301 | "ALTER TABLE users DROP COLUMN access\n" | |
3302 | "ALTER TABLE user_groups ADD system_access integer\n" | |
3303 | "UPDATE user_groups SET system_access=access\n" | |
3304 | "ALTER TABLE user_groups DROP COLUMN access\n" | |
3305 | "<END>"; | |
3306 | ||
3307 | if (!SQLBatch(m_szBatch)) | |
3308 | if (!g_bIgnoreErrors) | |
3309 | return FALSE; | |
3310 | ||
3311 | if (!SQLQuery(_T("UPDATE config SET var_value='28' WHERE var_name='DBFormatVersion'"))) | |
3312 | if (!g_bIgnoreErrors) | |
3313 | return FALSE; | |
3314 | ||
3315 | return TRUE; | |
3316 | } | |
3317 | ||
3318 | ||
3319 | // | |
3320 | // Move object data from class-specific tables to object_prioperties table | |
3321 | // | |
3322 | ||
3323 | static BOOL MoveObjectData(DWORD dwId, BOOL bInheritRights) | |
3324 | { | |
3325 | DB_RESULT hResult; | |
3326 | TCHAR szQuery[1024] ,szName[MAX_OBJECT_NAME]; | |
3327 | BOOL bRead = FALSE, bIsDeleted, bIsTemplate; | |
3328 | DWORD i, dwStatus, dwImageId; | |
3329 | static const TCHAR *m_pszTableNames[] = { _T("nodes"), _T("interfaces"), _T("subnets"), | |
3330 | _T("templates"), _T("network_services"), | |
3331 | _T("containers"), NULL }; | |
3332 | ||
3333 | // Try to read information from nodes table | |
3334 | for(i = 0; (!bRead) && (m_pszTableNames[i] != NULL); i++) | |
3335 | { | |
3336 | bIsTemplate = !_tcscmp(m_pszTableNames[i], _T("templates")); | |
3337 | _sntprintf(szQuery, 1024, _T("SELECT name,is_deleted,image_id%s FROM %s WHERE id=%d"), | |
3338 | bIsTemplate ? _T("") : _T(",status"), | |
3339 | m_pszTableNames[i], dwId); | |
3340 | hResult = SQLSelect(szQuery); | |
3341 | if (hResult != NULL) | |
3342 | { | |
3343 | if (DBGetNumRows(hResult) > 0) | |
3344 | { | |
3345 | DBGetField(hResult, 0, 0, szName, MAX_OBJECT_NAME); | |
3346 | bIsDeleted = DBGetFieldLong(hResult, 0, 1) ? TRUE : FALSE; | |
3347 | dwImageId = DBGetFieldULong(hResult, 0, 2); | |
3348 | dwStatus = bIsTemplate ? STATUS_UNKNOWN : DBGetFieldULong(hResult, 0, 3); | |
3349 | bRead = TRUE; | |
3350 | } | |
3351 | DBFreeResult(hResult); | |
3352 | } | |
3353 | else | |
3354 | { | |
3355 | if (!g_bIgnoreErrors) | |
3356 | return FALSE; | |
3357 | } | |
3358 | } | |
3359 | ||
3360 | if (bRead) | |
3361 | { | |
3362 | _sntprintf(szQuery, 1024, _T("INSERT INTO object_properties (object_id,name," | |
3363 | "status,is_deleted,image_id,inherit_access_rights," | |
3364 | "last_modified) VALUES (%d,'%s',%d,%d,%d,%d,%ld)"), | |
3365 | dwId, szName, dwStatus, bIsDeleted, dwImageId, bInheritRights, time(NULL)); | |
3366 | ||
3367 | if (!SQLQuery(szQuery)) | |
3368 | if (!g_bIgnoreErrors) | |
3369 | return FALSE; | |
3370 | } | |
3371 | else | |
3372 | { | |
3373 | _tprintf(_T("WARNING: object with ID %d presented in access control tables but cannot be found in data tables\n"), dwId); | |
3374 | } | |
3375 | ||
3376 | return TRUE; | |
3377 | } | |
3378 | ||
3379 | ||
3380 | // | |
3381 | // Upgrade from V26 to V27 | |
3382 | // | |
3383 | ||
31cc1924 | 3384 | static BOOL H_UpgradeFromV26(int currVersion, int newVersion) |
5039dede AK |
3385 | { |
3386 | DB_RESULT hResult; | |
3387 | DWORD i, dwNumObjects, dwId; | |
3388 | static TCHAR m_szBatch[] = | |
3389 | "ALTER TABLE nodes DROP COLUMN name\n" | |
3390 | "ALTER TABLE nodes DROP COLUMN status\n" | |
3391 | "ALTER TABLE nodes DROP COLUMN is_deleted\n" | |
3392 | "ALTER TABLE nodes DROP COLUMN image_id\n" | |
3393 | "ALTER TABLE interfaces DROP COLUMN name\n" | |
3394 | "ALTER TABLE interfaces DROP COLUMN status\n" | |
3395 | "ALTER TABLE interfaces DROP COLUMN is_deleted\n" | |
3396 | "ALTER TABLE interfaces DROP COLUMN image_id\n" | |
3397 | "ALTER TABLE subnets DROP COLUMN name\n" | |
3398 | "ALTER TABLE subnets DROP COLUMN status\n" | |
3399 | "ALTER TABLE subnets DROP COLUMN is_deleted\n" | |
3400 | "ALTER TABLE subnets DROP COLUMN image_id\n" | |
3401 | "ALTER TABLE network_services DROP COLUMN name\n" | |
3402 | "ALTER TABLE network_services DROP COLUMN status\n" | |
3403 | "ALTER TABLE network_services DROP COLUMN is_deleted\n" | |
3404 | "ALTER TABLE network_services DROP COLUMN image_id\n" | |
3405 | "ALTER TABLE containers DROP COLUMN name\n" | |
3406 | "ALTER TABLE containers DROP COLUMN status\n" | |
3407 | "ALTER TABLE containers DROP COLUMN is_deleted\n" | |
3408 | "ALTER TABLE containers DROP COLUMN image_id\n" | |
3409 | "ALTER TABLE templates DROP COLUMN name\n" | |
3410 | "ALTER TABLE templates DROP COLUMN is_deleted\n" | |
3411 | "ALTER TABLE templates DROP COLUMN image_id\n" | |
3412 | "DROP TABLE access_options\n" | |
3413 | "DELETE FROM config WHERE var_name='TopologyRootObjectName'\n" | |
3414 | "DELETE FROM config WHERE var_name='TopologyRootImageId'\n" | |
3415 | "DELETE FROM config WHERE var_name='ServiceRootObjectName'\n" | |
3416 | "DELETE FROM config WHERE var_name='ServiceRootImageId'\n" | |
3417 | "DELETE FROM config WHERE var_name='TemplateRootObjectName'\n" | |
3418 | "DELETE FROM config WHERE var_name='TemplateRootImageId'\n" | |
3419 | "INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) " | |
3420 | "VALUES (31,'SYS_SNMP_OK',0,1,'Connectivity with SNMP agent restored'," | |
3421 | "'Generated when connectivity with node#27s SNMP agent restored.#0D#0A" | |
3422 | "Parameters:#0D#0A No message-specific parameters')\n" | |
3423 | "INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) " | |
3424 | "VALUES (32,'SYS_AGENT_OK',0,1,'Connectivity with native agent restored'," | |
3425 | "'Generated when connectivity with node#27s native agent restored.#0D#0A" | |
3426 | "Parameters:#0D#0A No message-specific parameters')\n" | |
3427 | "<END>"; | |
3428 | ||
3429 | if (!CreateTable(_T("CREATE TABLE object_properties (" | |
3430 | "object_id integer not null," | |
3431 | "name varchar(63) not null," | |
3432 | "status integer not null," | |
3433 | "is_deleted integer not null," | |
3434 | "image_id integer," | |
3435 | "last_modified integer not null," | |
3436 | "inherit_access_rights integer not null," | |
3437 | "PRIMARY KEY(object_id))"))) | |
3438 | if (!g_bIgnoreErrors) | |
3439 | return FALSE; | |
3440 | ||
3441 | if (!CreateTable(_T("CREATE TABLE user_profiles (" | |
3442 | "user_id integer not null," | |
3443 | "var_name varchar(255) not null," | |
3444 | "var_value $SQL:TEXT," | |
3445 | "PRIMARY KEY(user_id,var_name))"))) | |
3446 | if (!g_bIgnoreErrors) | |
3447 | return FALSE; | |
3448 | ||
3449 | // Move data from access_options and class-specific tables to object_properties | |
3450 | hResult = SQLSelect(_T("SELECT object_id,inherit_rights FROM access_options")); | |
3451 | if (hResult != NULL) | |
3452 | { | |
3453 | dwNumObjects = DBGetNumRows(hResult); | |
3454 | for(i = 0; i < dwNumObjects; i++) | |
3455 | { | |
3456 | dwId = DBGetFieldULong(hResult, i, 0); | |
3457 | if (dwId >= 10) // Id below 10 reserved for built-in objects | |
3458 | { | |
3459 | if (!MoveObjectData(dwId, DBGetFieldLong(hResult, i, 1) ? TRUE : FALSE)) | |
3460 | { | |
3461 | DBFreeResult(hResult); | |
3462 | return FALSE; | |
3463 | } | |
3464 | } | |
3465 | else | |
3466 | { | |
3467 | TCHAR szName[MAX_OBJECT_NAME], szQuery[1024]; | |
3468 | DWORD dwImageId; | |
3469 | BOOL bValidObject = TRUE; | |
3470 | ||
3471 | switch(dwId) | |
3472 | { | |
3473 | case 1: // Topology Root | |
3474 | ConfigReadStr(_T("TopologyRootObjectName"), szName, | |
3475 | MAX_OBJECT_NAME, _T("Entire Network")); | |
3476 | dwImageId = ConfigReadULong(_T("TopologyRootImageId"), 0); | |
3477 | break; | |
3478 | case 2: // Service Root | |
3479 | ConfigReadStr(_T("ServiceRootObjectName"), szName, | |
3480 | MAX_OBJECT_NAME, _T("All Services")); | |
3481 | dwImageId = ConfigReadULong(_T("ServiceRootImageId"), 0); | |
3482 | break; | |
3483 | case 3: // Template Root | |
3484 | ConfigReadStr(_T("TemplateRootObjectName"), szName, | |
3485 | MAX_OBJECT_NAME, _T("All Services")); | |
3486 | dwImageId = ConfigReadULong(_T("TemplateRootImageId"), 0); | |
3487 | break; | |
3488 | default: | |
3489 | bValidObject = FALSE; | |
3490 | break; | |
3491 | } | |
3492 | ||
3493 | if (bValidObject) | |
3494 | { | |
3495 | _sntprintf(szQuery, 1024, _T("INSERT INTO object_properties (object_id,name," | |
3496 | "status,is_deleted,image_id,inherit_access_rights," | |
3497 | "last_modified) VALUES (%d,'%s',5,0,%d,%d,%ld)"), | |
3498 | dwId, szName, dwImageId, | |
3499 | DBGetFieldLong(hResult, i, 1) ? TRUE : FALSE, | |
3500 | time(NULL)); | |
3501 | ||
3502 | if (!SQLQuery(szQuery)) | |
3503 | if (!g_bIgnoreErrors) | |
3504 | return FALSE; | |
3505 | } | |
3506 | else | |
3507 | { | |
3508 | _tprintf(_T("WARNING: Invalid built-in object ID %d\n"), dwId); | |
3509 | } | |
3510 | } | |
3511 | } | |
3512 | DBFreeResult(hResult); | |
3513 | } | |
3514 | else | |
3515 | { | |
3516 | if (!g_bIgnoreErrors) | |
3517 | return FALSE; | |
3518 | } | |
3519 | ||
3520 | if (!SQLBatch(m_szBatch)) | |
3521 | if (!g_bIgnoreErrors) | |
3522 | return FALSE; | |
3523 | ||
3524 | if (!SQLQuery(_T("UPDATE config SET var_value='27' WHERE var_name='DBFormatVersion'"))) | |
3525 | if (!g_bIgnoreErrors) | |
3526 | return FALSE; | |
3527 | ||
3528 | return TRUE; | |
3529 | } | |
3530 | ||
3531 | ||
3532 | // | |
3533 | // Upgrade from V25 to V26 | |
3534 | // | |
3535 | ||
31cc1924 | 3536 | static BOOL H_UpgradeFromV25(int currVersion, int newVersion) |
5039dede AK |
3537 | { |
3538 | DB_RESULT hResult; | |
3539 | TCHAR szTemp[512]; | |
3540 | ||
3541 | hResult = SQLSelect(_T("SELECT var_value FROM config WHERE var_name='IDataIndexCreationCommand'")); | |
3542 | if (hResult != NULL) | |
3543 | { | |
3544 | if (DBGetNumRows(hResult) > 0) | |
3545 | { | |
3546 | if (!CreateConfigParam(_T("IDataIndexCreationCommand_0"), | |
3547 | DBGetField(hResult, 0, 0, szTemp, 512), 0, 1)) | |
3548 | { | |
3549 | if (!g_bIgnoreErrors) | |
3550 | { | |
3551 | DBFreeResult(hResult); | |
3552 | return FALSE; | |
3553 | } | |
3554 | } | |
3555 | } | |
3556 | DBFreeResult(hResult); | |
3557 | ||
3558 | if (!SQLQuery(_T("DELETE FROM config WHERE var_name='IDataIndexCreationCommand'"))) | |
3559 | if (!g_bIgnoreErrors) | |
3560 | return FALSE; | |
3561 | } | |
3562 | ||
3563 | if (!CreateConfigParam(_T("IDataIndexCreationCommand_1"), | |
3564 | _T("CREATE INDEX idx_timestamp ON idata_%d(idata_timestamp)"), 0, 1)) | |
3565 | if (!g_bIgnoreErrors) | |
3566 | return FALSE; | |
3567 | ||
3568 | if (!SQLQuery(_T("UPDATE config SET var_value='26' WHERE var_name='DBFormatVersion'"))) | |
3569 | if (!g_bIgnoreErrors) | |
3570 | return FALSE; | |
3571 | ||
3572 | return TRUE; | |
3573 | } | |
3574 | ||
3575 | ||
3576 | // | |
3577 | // Upgrade from V24 to V25 | |
3578 | // | |
3579 | ||
31cc1924 | 3580 | static BOOL H_UpgradeFromV24(int currVersion, int newVersion) |
5039dede AK |
3581 | { |
3582 | DB_RESULT hResult; | |
3583 | int i, iNumRows; | |
3584 | DWORD dwNodeId; | |
3585 | TCHAR szQuery[256]; | |
3586 | ||
a4743a0f | 3587 | if (GetYesNo(_T("Create indexes on existing IDATA tables?"))) |
5039dede AK |
3588 | { |
3589 | hResult = SQLSelect(_T("SELECT id FROM nodes WHERE is_deleted=0")); | |
3590 | if (hResult != NULL) | |
3591 | { | |
3592 | iNumRows = DBGetNumRows(hResult); | |
3593 | for(i = 0; i < iNumRows; i++) | |
3594 | { | |
3595 | dwNodeId = DBGetFieldULong(hResult, i, 0); | |
3596 | _tprintf(_T("Creating indexes for table \"idata_%d\"...\n"), dwNodeId); | |
3597 | _sntprintf(szQuery, 256, _T("CREATE INDEX idx_timestamp ON idata_%d(idata_timestamp)"), dwNodeId); | |
3598 | if (!SQLQuery(szQuery)) | |
3599 | if (!g_bIgnoreErrors) | |
3600 | { | |
3601 | DBFreeResult(hResult); | |
3602 | return FALSE; | |
3603 | } | |
3604 | } | |
3605 | DBFreeResult(hResult); | |
3606 | } | |
3607 | else | |
3608 | { | |
3609 | if (!g_bIgnoreErrors) | |
3610 | return FALSE; | |
3611 | } | |
3612 | } | |
3613 | ||
3614 | if (!SQLQuery(_T("UPDATE config SET var_value='25' WHERE var_name='DBFormatVersion'"))) | |
3615 | if (!g_bIgnoreErrors) | |
3616 | return FALSE; | |
3617 | ||
3618 | return TRUE; | |
3619 | } | |
3620 | ||
3621 | ||
3622 | // | |
3623 | // Upgrade from V23 to V24 | |
3624 | // | |
3625 | ||
31cc1924 | 3626 | static BOOL H_UpgradeFromV23(int currVersion, int newVersion) |
5039dede AK |
3627 | { |
3628 | DB_RESULT hResult; | |
3629 | TCHAR szQuery[256]; | |
3630 | int i, iNumRows; | |
3631 | ||
3632 | if (!CreateTable(_T("CREATE TABLE raw_dci_values (" | |
3633 | " item_id integer not null," | |
3634 | " raw_value varchar(255)," | |
3635 | " last_poll_time integer," | |
3636 | " PRIMARY KEY(item_id))"))) | |
3637 | if (!g_bIgnoreErrors) | |
3638 | return FALSE; | |
3639 | ||
3640 | if (!SQLQuery(_T("CREATE INDEX idx_item_id ON raw_dci_values(item_id)"))) | |
3641 | if (!g_bIgnoreErrors) | |
3642 | return FALSE; | |
3643 | ||
3644 | ||
3645 | // Create empty records in raw_dci_values for all existing DCIs | |
3646 | hResult = SQLSelect(_T("SELECT item_id FROM items")); | |
3647 | if (hResult != NULL) | |
3648 | { | |
3649 | iNumRows = DBGetNumRows(hResult); | |
3650 | for(i = 0; i < iNumRows; i++) | |
3651 | { | |
3652 | _stprintf(szQuery, _T("INSERT INTO raw_dci_values (item_id," | |
3653 | "raw_value,last_poll_time) VALUES (%d,'#00',1)"), | |
3654 | DBGetFieldULong(hResult, i, 0)); | |
3655 | if (!SQLQuery(szQuery)) | |
3656 | if (!g_bIgnoreErrors) | |
3657 | { | |
3658 | DBFreeResult(hResult); | |
3659 | return FALSE; | |
3660 | } | |
3661 | } | |
3662 | DBFreeResult(hResult); | |
3663 | } | |
3664 | else | |
3665 | { | |
3666 | if (!g_bIgnoreErrors) | |
3667 | return FALSE; | |
3668 | } | |
3669 | ||
3670 | if (!SQLQuery(_T("UPDATE config SET var_value='24' WHERE var_name='DBFormatVersion'"))) | |
3671 | if (!g_bIgnoreErrors) | |
3672 | return FALSE; | |
3673 | ||
3674 | return TRUE; | |
3675 | } | |
3676 | ||
3677 | ||
3678 | // | |
3679 | // Upgrade from V22 to V23 | |
3680 | // | |
3681 | ||
31cc1924 | 3682 | static BOOL H_UpgradeFromV22(int currVersion, int newVersion) |
5039dede AK |
3683 | { |
3684 | static TCHAR m_szBatch[] = | |
3685 | "ALTER TABLE items ADD template_item_id integer\n" | |
3686 | "UPDATE items SET template_item_id=0\n" | |
3687 | "CREATE INDEX idx_sequence ON thresholds(sequence_number)\n" | |
3688 | "<END>"; | |
3689 | ||
3690 | if (!SQLBatch(m_szBatch)) | |
3691 | if (!g_bIgnoreErrors) | |
3692 | return FALSE; | |
3693 | ||
3694 | if (!SQLQuery(_T("UPDATE config SET var_value='23' WHERE var_name='DBFormatVersion'"))) | |
3695 | if (!g_bIgnoreErrors) | |
3696 | return FALSE; | |
3697 | ||
3698 | return TRUE; | |
3699 | } | |
3700 | ||
3701 |