changeset 56:4f66bc893fc3

Fix Debian issue #906771
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 03 Sep 2018 16:23:20 +0200
parents 89f6f2a98016
children f4d5c2c70f98
files PostgreSQL/NEWS PostgreSQL/Plugins/PostgreSQLIndex.cpp
diffstat 2 files changed, 16 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/PostgreSQL/NEWS	Wed Aug 22 18:07:22 2018 +0200
+++ b/PostgreSQL/NEWS	Mon Sep 03 16:23:20 2018 +0200
@@ -1,6 +1,8 @@
 Pending changes in the mainline
 ===============================
 
+* Fix Debian issue #906771 (Uncaught exception prevents db intialization
+  (likely related to pg_trgm))
 * Fix: Catching exceptions in destructors
 
 
--- a/PostgreSQL/Plugins/PostgreSQLIndex.cpp	Wed Aug 22 18:07:22 2018 +0200
+++ b/PostgreSQL/Plugins/PostgreSQLIndex.cpp	Mon Sep 03 16:23:20 2018 +0200
@@ -113,6 +113,18 @@
         SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabasePatchLevel, revision);
       }
 
+      if (revision != 1)
+      {
+        LOG(ERROR) << "PostgreSQL plugin is incompatible with database schema revision: " << revision;
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);        
+      }
+
+      t.Commit();
+    }
+
+    {
+      PostgreSQLTransaction t(*db);
+
       int hasTrigram = 0;
       if (!LookupGlobalIntegerProperty(hasTrigram, *db, t, Orthanc::GlobalProperty_HasTrigramIndex) ||
           hasTrigram != 1)
@@ -139,6 +151,8 @@
 
           SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_HasTrigramIndex, 1);
           LOG(WARNING) << "Trigram index has been created";
+
+          t.Commit();
         }
         catch (Orthanc::OrthancException&)
         {
@@ -148,14 +162,6 @@
                        << "PostgreSQL server, e.g. on Debian: sudo apt install postgresql-contrib";
         }
       }
-
-      if (revision != 1)
-      {
-        LOG(ERROR) << "PostgreSQL plugin is incompatible with database schema revision: " << revision;
-        throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);        
-      }
-
-      t.Commit();
     }
 
     return db.release();