added compatibility checks in DB upgrade procedure for rack rear view (issue #NX...
authorVictor Kirhenshtein <victor@netxms.org>
Fri, 24 Nov 2017 12:37:22 +0000 (14:37 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Fri, 24 Nov 2017 12:37:22 +0000 (14:37 +0200)
src/server/tools/nxdbmgr/upgrade_v21.cpp
src/server/tools/nxdbmgr/upgrade_v22.cpp
src/server/tools/nxdbmgr/upgrade_v30.cpp

index add31b7..9a61844 100644 (file)
 #include "nxdbmgr.h"
 
 /**
- * Upgrade from 21.4 to 30.0
+ * Upgrade from 21.5 to 30.0
  */
-static bool H_UpgradeFromV4()
+static bool H_UpgradeFromV5()
 {
    CHK_EXEC(SetMajorSchemaVersion(30, 0));
    return true;
 }
 
 /**
+ * Upgrade from 21.4 to 21.5
+ */
+static bool H_UpgradeFromV4()
+{
+   static const TCHAR *batch =
+            _T("ALTER TABLE nodes ADD rack_orientation integer\n")
+            _T("ALTER TABLE chassis ADD rack_orientation integer\n")
+            _T("UPDATE nodes SET rack_orientation=0\n")
+            _T("UPDATE chassis SET rack_orientation=0\n")
+            _T("<END>");
+   CHK_EXEC(SQLBatch(batch));
+
+   CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("nodes"), _T("rack_orientation")));
+   CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("chassis"), _T("rack_orientation")));
+
+   CHK_EXEC(SetMinorSchemaVersion(5));
+   return true;
+}
+
+/**
  * Upgrade from 21.3 to 21.4
  */
 static bool H_UpgradeFromV3()
@@ -121,7 +141,8 @@ static struct
    bool (* upgradeProc)();
 } s_dbUpgradeMap[] =
 {
-   { 4, 30, 0, H_UpgradeFromV4 },
+   { 5, 30, 0, H_UpgradeFromV5 },
+   { 4, 21, 5, H_UpgradeFromV4 },
    { 3, 21, 4, H_UpgradeFromV3 },
    { 2, 21, 3, H_UpgradeFromV2 },
    { 1, 21, 2, H_UpgradeFromV1 },
index 83e1be8..8f41cd4 100644 (file)
 #include "nxdbmgr.h"
 
 /**
- * Upgrade from 22.3 to 30.0
+ * Upgrade from 22.4 to 30.0
  */
-static bool H_UpgradeFromV3()
+static bool H_UpgradeFromV4()
 {
    CHK_EXEC(SetMajorSchemaVersion(30, 0));
    return true;
 }
 
 /**
+ * Upgrade from 22.3 to 22.4
+ */
+static bool H_UpgradeFromV3()
+{
+   if (GetSchemaLevelForMajorVersion(21) < 5)
+   {
+      static const TCHAR *batch =
+               _T("ALTER TABLE nodes ADD rack_orientation integer\n")
+               _T("ALTER TABLE chassis ADD rack_orientation integer\n")
+               _T("UPDATE nodes SET rack_orientation=0\n")
+               _T("UPDATE chassis SET rack_orientation=0\n")
+               _T("<END>");
+      CHK_EXEC(SQLBatch(batch));
+
+      CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("nodes"), _T("rack_orientation")));
+      CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("chassis"), _T("rack_orientation")));
+
+      CHK_EXEC(SetSchemaLevelForMajorVersion(21, 5));
+   }
+   CHK_EXEC(SetMinorSchemaVersion(4));
+   return true;
+}
+
+/**
  * Upgrade from 22.2 to 22.3
  */
 static bool H_UpgradeFromV2()
@@ -82,7 +106,8 @@ static struct
    bool (* upgradeProc)();
 } s_dbUpgradeMap[] =
 {
-   { 3, 30, 0, H_UpgradeFromV3 },
+   { 4, 30, 0, H_UpgradeFromV4 },
+   { 3, 22, 4, H_UpgradeFromV3 },
    { 2, 22, 3, H_UpgradeFromV2 },
    { 1, 22, 2, H_UpgradeFromV1 },
    { 0, 22, 1, H_UpgradeFromV0 },
index ed29ba8..8a89d7e 100644 (file)
@@ -45,21 +45,26 @@ static bool H_UpgradeFromV13()
 }
 
 /**
- * Upgrade from 30.12 to 30.13
+ * Upgrade from 30.12 to 30.13  (changes also included into 21.5 and 22.4)
  */
 static bool H_UpgradeFromV12()
 {
-   static const TCHAR *batch =
-            _T("ALTER TABLE nodes ADD rack_orientation integer\n")
-            _T("ALTER TABLE chassis ADD rack_orientation integer\n")
-            _T("UPDATE nodes SET rack_orientation=0\n")
-            _T("UPDATE chassis SET rack_orientation=0\n")
-            _T("<END>");
-   CHK_EXEC(SQLBatch(batch));
+   if ((GetSchemaLevelForMajorVersion(21) < 5) && (GetSchemaLevelForMajorVersion(22) < 4))
+   {
+      static const TCHAR *batch =
+               _T("ALTER TABLE nodes ADD rack_orientation integer\n")
+               _T("ALTER TABLE chassis ADD rack_orientation integer\n")
+               _T("UPDATE nodes SET rack_orientation=0\n")
+               _T("UPDATE chassis SET rack_orientation=0\n")
+               _T("<END>");
+      CHK_EXEC(SQLBatch(batch));
 
-   CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("nodes"), _T("rack_orientation")));
-   CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("chassis"), _T("rack_orientation")));
+      CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("nodes"), _T("rack_orientation")));
+      CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("chassis"), _T("rack_orientation")));
 
+      CHK_EXEC(SetSchemaLevelForMajorVersion(22, 4));
+      CHK_EXEC(SetSchemaLevelForMajorVersion(21, 5));
+   }
    CHK_EXEC(SetMinorSchemaVersion(13));
    return true;
 }