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