[PATCH] Add new DB Version check and fix impossible check

View previous topic View next topic Go down

[PATCH] Add new DB Version check and fix impossible check

Post by Cometo on Mon Oct 24, 2016 9:58 am

Request for comments on db version check during server startup

Code:

Index: src/eve-server/ServiceDB.cpp
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/eve-server/ServiceDB.cpp    (revision c0dffa287340bfd0565f0d801aab7f1f5dbfdf54)
+++ src/eve-server/ServiceDB.cpp    (revision )
@@ -548,6 +548,18 @@
     }
 }
 
+bool ServiceDB::VerifyDatabaseVersion(int buildDBVersion){
+    DBQueryResult res;
+    if(!DBcore::RunQuery(res, "SELECT `config_name`, `config_value` FROM `srvStatus` WHERE `config_name` = 'databaseVersion';"))
+    {
+        return false;
+    }
 
+    DBResultRow row;
+    if(!res.GetRow(row)) {
+        return false;
+    }
 
-
+    int dbVersion = std::stoi(row.getTextNC(1));
+    return dbVersion == buildDBVersion;
+}
Index: src/eve-server/ServiceDB.h
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/eve-server/ServiceDB.h  (revision c0dffa287340bfd0565f0d801aab7f1f5dbfdf54)
+++ src/eve-server/ServiceDB.h  (revision )
@@ -86,6 +86,7 @@
 
     static void SetAccountOnlineStatus(uint32 accountID, bool onoff_status);
     static void SetAccountBanStatus(uint32 accountID, bool onoff_status);
+    static bool VerifyDatabaseVersion(int buildDBVersion);
 
 protected:
     static void ProcessStringChange(const char * key, const std::string & oldValue, const std::string & newValue, PyDict * notif, std::vector<std::string> & dbQ);
Index: src/eve-server/eve-server.cpp
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/eve-server/eve-server.cpp   (revision c0dffa287340bfd0565f0d801aab7f1f5dbfdf54)
+++ src/eve-server/eve-server.cpp   (revision )
@@ -174,6 +174,7 @@
 
 static const char* const CONFIG_FILE = EVEMU_ROOT "/etc/eve-server.xml";
 static const uint32 MAIN_LOOP_DELAY = 10; // delay 10 ms.
+static const int DB_VERSION = 1;
 
 static volatile bool RunLoops = true;
 dgmtypeattributemgr * _sDgmTypeAttrMgr;
@@ -250,10 +251,15 @@
         std::cout << std::endl << "Exiting";
         return 1;
     }
-    else if (DBcore::Connected)
+    else if (DBcore::GetStatus() == DBcore::Connected)
     {
         SysLog::Success("Server Init", "Connected to database successfully");
     }
+
+    if(ServiceDB::VerifyDatabaseVersion(DB_VERSION))
+        SysLog::Success("Server Init", "Verified db version successfully");
+    else
+        SysLog::Error("Server Init", "Incorrect db version detected, continue at own risk.");
 
     _sDgmTypeAttrMgr = new dgmtypeattributemgr(); // needs to be after db init as its using it

This also requiresa decision on where the databaseVersion value should be inserted into the db.
Code:
INSERT INTO `evemu_july`.`srvStatus` (`config_name`, `config_value`) VALUES ('databaseVersiona', '1');

Cometo

Posts : 5
Join date : 2016-05-31

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum