DB upgrade compatibility for 2.2; added missing configuration parameter INstanceReten...
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 28 Nov 2017 12:36:56 +0000 (14:36 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 28 Nov 2017 12:36:56 +0000 (14:36 +0200)
sql/setup.in
src/server/core/dctarget.cpp
src/server/tools/nxdbmgr/upgrade_v22.cpp
src/server/tools/nxdbmgr/upgrade_v30.cpp

index bc502bb..17b1e31 100644 (file)
@@ -94,6 +94,7 @@ INSERT INTO config (var_name,var_value,default_value,is_visible,need_server_rest
 INSERT INTO config (var_name,var_value,default_value,is_visible,need_server_restart,data_type,description) VALUES ('IcmpPingTimeout','1500','1500',1,1,'I','Timeout for ICMP ping used for status polls (in milliseconds).');
 INSERT INTO config (var_name,var_value,default_value,is_visible,need_server_restart,data_type,description) VALUES ('ImportConfigurationOnStartup','1','1',1,1,'B','Import configuration from local files on server startup.');
 INSERT INTO config (var_name,var_value,default_value,is_visible,need_server_restart,data_type,description) VALUES ('InstancePollingInterval','600','600',1,1,'I','Instance polling interval (in seconds).');
+INSERT INTO config (var_name,var_value,default_value,is_visible,need_server_restart,data_type,description) VALUES ('InstanceRetentionTime','0','0',1,1,'I','Default retention time (in days) for missing DCI instances');
 INSERT INTO config (var_name,var_value,default_value,is_visible,need_server_restart,data_type,description) VALUES ('InternalCA','0','0',1,1,'B','Enable/disable internal certificate authority.');
 INSERT INTO config (var_name,var_value,default_value,is_visible,need_server_restart,data_type,description) VALUES ('IntruderLockoutThreshold','0','0',1,0,'I','');
 INSERT INTO config (var_name,var_value,default_value,is_visible,need_server_restart,data_type,description) VALUES ('IntruderLockoutTime','30','30',1,0,'I','');
index ec530c6..cc73fc2 100644 (file)
@@ -1647,13 +1647,12 @@ bool DataCollectionTarget::updateInstances(DCObject *root, StringMap *instances,
             object->updateFromTemplate(root);
             changed = true;
          }
-         instances->remove(dcoInstance);
-
          if (object->getInstanceGracePeriodStart() > 0)
          {
             object->setInstanceGracePeriodStart(0);
             object->setStatus(ITEM_STATUS_ACTIVE, false);
          }
+         instances->remove(dcoInstance);
       }
       else
       {
index 8f41cd4..4c850cc 100644 (file)
 #include "nxdbmgr.h"
 
 /**
- * Upgrade from 22.4 to 30.0
+ * Upgrade from 22.5 to 30.0
  */
-static bool H_UpgradeFromV4()
+static bool H_UpgradeFromV5()
 {
    CHK_EXEC(SetMajorSchemaVersion(30, 0));
    return true;
 }
 
 /**
+ * Upgrade from 22.4 to 22.5
+ */
+static bool H_UpgradeFromV4()
+{
+   static const TCHAR *batch =
+            _T("ALTER TABLE items ADD instance_retention_time integer\n")
+            _T("ALTER TABLE dc_tables ADD instance_retention_time integer\n")
+            _T("UPDATE items SET instance_retention_time=-1\n")
+            _T("UPDATE dc_tables SET instance_retention_time=-1\n")
+            _T("INSERT INTO config (var_name,var_value,default_value,is_visible,need_server_restart,is_public,data_type,description) ")
+            _T("VALUES ('InstanceRetentionTime','0','0',1,1,'Y','I','Default retention time (in days) for missing DCI instances')\n")
+            _T("<END>");
+   CHK_EXEC(SQLBatch(batch));
+
+   CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("items"), _T("instance_retention_time")));
+   CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("dc_tables"), _T("instance_retention_time")));
+
+   CHK_EXEC(SetMinorSchemaVersion(5));
+   return true;
+}
+
+/**
  * Upgrade from 22.3 to 22.4
  */
 static bool H_UpgradeFromV3()
@@ -106,7 +128,8 @@ static struct
    bool (* upgradeProc)();
 } s_dbUpgradeMap[] =
 {
-   { 4, 30, 0, H_UpgradeFromV4 },
+   { 5, 30, 0, H_UpgradeFromV5 },
+   { 4, 22, 5, H_UpgradeFromV4 },
    { 3, 22, 4, H_UpgradeFromV3 },
    { 2, 22, 3, H_UpgradeFromV2 },
    { 1, 22, 2, H_UpgradeFromV1 },
index 8a89d7e..b2da38b 100644 (file)
 #include "nxdbmgr.h"
 
 /**
- * Upgrade from 30.13 to 30.14
+ * Upgrade from 30.13 to 30.14 (changes also included into 22.5)
  */
 static bool H_UpgradeFromV13()
 {
-   static const TCHAR *batch = 
-            _T("ALTER TABLE items ADD instance_retention_time integer\n")
-            _T("ALTER TABLE dc_tables ADD instance_retention_time integer\n")
-            _T("UPDATE items SET instance_retention_time=-1\n")
-            _T("UPDATE dc_tables SET instance_retention_time=-1\n")
-            _T("INSERT INTO config (var_name,var_value,default_value,is_visible,need_server_restart,is_public,data_type,description) ")
-            _T("VALUES ('InstanceRetentionTime','0','0',1,1,'Y','I','Time, in days, for instance DCO retention')\n")
-            _T("<END>");
-   CHK_EXEC(SQLBatch(batch));
-
-   CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("items"), _T("instance_retention_time")));
-   CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("dc_tables"), _T("instance_retention_time")));
+   if (GetSchemaLevelForMajorVersion(22) < 5)
+   {
+      static const TCHAR *batch =
+               _T("ALTER TABLE items ADD instance_retention_time integer\n")
+               _T("ALTER TABLE dc_tables ADD instance_retention_time integer\n")
+               _T("UPDATE items SET instance_retention_time=-1\n")
+               _T("UPDATE dc_tables SET instance_retention_time=-1\n")
+               _T("INSERT INTO config (var_name,var_value,default_value,is_visible,need_server_restart,is_public,data_type,description) ")
+               _T("VALUES ('InstanceRetentionTime','0','0',1,1,'Y','I','Default retention time (in days) for missing DCI instances')\n")
+               _T("<END>");
+      CHK_EXEC(SQLBatch(batch));
 
+      CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("items"), _T("instance_retention_time")));
+      CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("dc_tables"), _T("instance_retention_time")));
+   }
    CHK_EXEC(SetMinorSchemaVersion(14));
    return true;
 }