8e407e272cff7765a2c81b18360c5c0bc68f7b8e
[public/netxms.git] / src / server / tools / nxdbmgr / upgrade_v22.cpp
1 /*
2 ** nxdbmgr - NetXMS database manager
3 ** Copyright (C) 2004-2017 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 ** File: upgrade_v22.cpp
20 **
21 **/
22
23 #include "nxdbmgr.h"
24
25 /**
26 * Upgrade from 22.1 to 30.0
27 */
28 static bool H_UpgradeFromV1()
29 {
30 CHK_EXEC(SetMajorSchemaVersion(30, 0));
31 return true;
32 }
33
34 /**
35 * Upgrade map
36 */
37 static struct
38 {
39 int version;
40 int nextMajor;
41 int nextMinor;
42 bool (* upgradeProc)();
43 } s_dbUpgradeMap[] =
44 {
45 { 1, 30, 0, H_UpgradeFromV1 },
46 { 0, 0, 0, NULL }
47 };
48
49 /**
50 * Upgrade database to new version
51 */
52 bool MajorSchemaUpgrade_V22()
53 {
54 INT32 major, minor;
55 if (!DBGetSchemaVersion(g_hCoreDB, &major, &minor))
56 return false;
57
58 while(major == 21)
59 {
60 // Find upgrade procedure
61 int i;
62 for(i = 0; s_dbUpgradeMap[i].upgradeProc != NULL; i++)
63 if (s_dbUpgradeMap[i].version == minor)
64 break;
65 if (s_dbUpgradeMap[i].upgradeProc == NULL)
66 {
67 _tprintf(_T("Unable to find upgrade procedure for version 22.%d\n"), minor);
68 return false;
69 }
70 _tprintf(_T("Upgrading from version 22.%d to %d.%d\n"), minor, s_dbUpgradeMap[i].nextMajor, s_dbUpgradeMap[i].nextMinor);
71 DBBegin(g_hCoreDB);
72 if (s_dbUpgradeMap[i].upgradeProc())
73 {
74 DBCommit(g_hCoreDB);
75 if (!DBGetSchemaVersion(g_hCoreDB, &major, &minor))
76 return false;
77 }
78 else
79 {
80 _tprintf(_T("Rolling back last stage due to upgrade errors...\n"));
81 DBRollback(g_hCoreDB);
82 return false;
83 }
84 }
85 return true;
86 }