# HG changeset patch # User Alain Mazy # Date 1759927635 -7200 # Node ID 176e5dfbad433a60fa2c3a60d65816d4b401e118 # Parent fc41dc50407390e2183ce63ec81d28d259139cac revert: check revision inside the transaction AND outside diff -r fc41dc504073 -r 176e5dfbad43 PostgreSQL/Plugins/PostgreSQLIndex.cpp --- a/PostgreSQL/Plugins/PostgreSQLIndex.cpp Wed Oct 08 12:48:04 2025 +0200 +++ b/PostgreSQL/Plugins/PostgreSQLIndex.cpp Wed Oct 08 14:47:15 2025 +0200 @@ -273,8 +273,22 @@ LOG(WARNING) << "Upgrading DB schema by applying PrepareIndex.sql"; // apply all idempotent changes that are in the PrepareIndex.sql ApplyPrepareIndex(t, manager); + + // first check that the patch level has been upgraded correctly before we commit the transaction ! + if (!LookupGlobalIntegerProperty(currentRevision, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel)) + { + LOG(ERROR) << "No Database revision found after the upgrade !"; + throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); + } + + LOG(WARNING) << "Database revision after the upgrade (1) is " << currentRevision; + + if (currentRevision != CURRENT_DB_REVISION) + { + LOG(ERROR) << "Invalid database revision after the upgrade (1) !"; + throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); + } } - } t.Commit(); @@ -288,12 +302,12 @@ if (!LookupGlobalIntegerProperty(currentRevision, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel)) { - LOG(ERROR) << "No Database revision found after the upgrade !"; + LOG(ERROR) << "No Database revision found after the upgrade (2) !"; throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); } LookupGlobalIntegerProperty(currentRevision, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel); - LOG(WARNING) << "Database revision after the upgrade is " << currentRevision; + LOG(WARNING) << "Database revision after the upgrade (2) is " << currentRevision; if (currentRevision != CURRENT_DB_REVISION) {