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