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