diff Plugins/Engine/OrthancPluginDatabase.cpp @ 1615:c40fe92a68e7

Primitives to upgrade the database version in plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 16 Sep 2015 15:18:59 +0200
parents c74495267acf
children 0a2ad4a6858f
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPluginDatabase.cpp	Fri Sep 11 18:46:13 2015 +0200
+++ b/Plugins/Engine/OrthancPluginDatabase.cpp	Wed Sep 16 15:18:59 2015 +0200
@@ -982,6 +982,43 @@
   }
 
 
+  unsigned int OrthancPluginDatabase::GetDatabaseVersion()
+  {
+    if (extensions_.getDatabaseVersion != NULL)
+    {
+      uint32_t version;
+      if (extensions_.getDatabaseVersion(&version, payload_) != 0)
+      {
+        throw OrthancException(ErrorCode_Plugin);
+      }
+
+      return version;
+    }
+    else
+    {
+      // Before adding the "GetDatabaseVersion()" extension in plugins
+      // (OrthancPostgreSQL <= 1.2), the only supported DB schema was
+      // version 5.
+      return 5;
+    }
+  }
+
+
+  void OrthancPluginDatabase::Upgrade(unsigned int targetVersion,
+                                      IStorageArea& storageArea)
+  {
+    if (extensions_.upgradeDatabase != NULL)
+    {
+      if (extensions_.upgradeDatabase(
+            payload_, targetVersion, 
+            reinterpret_cast<OrthancPluginStorageArea*>(&storageArea)) != 0)
+      {
+        throw OrthancException(ErrorCode_Plugin);
+      }
+    }
+  }
+
+
   void OrthancPluginDatabase::AnswerReceived(const _OrthancPluginDatabaseAnswer& answer)
   {
     if (answer.type == _OrthancPluginDatabaseAnswerType_None)