# HG changeset patch # User Sebastien Jodogne # Date 1354708225 -3600 # Node ID bd009f0b1931464979040a7aa982cf12b4190ecd # Parent 4dc9d00c359c24016dbda89a5d151b090c19c7b7 db version diff -r 4dc9d00c359c -r bd009f0b1931 Core/Enumerations.h --- a/Core/Enumerations.h Wed Dec 05 12:32:43 2012 +0100 +++ b/Core/Enumerations.h Wed Dec 05 12:50:25 2012 +0100 @@ -54,7 +54,8 @@ ErrorCode_CannotWriteFile, ErrorCode_BadFileFormat, ErrorCode_Timeout, - ErrorCode_UnknownResource + ErrorCode_UnknownResource, + ErrorCode_IncompatibleDatabaseVersion }; enum PixelFormat diff -r 4dc9d00c359c -r bd009f0b1931 Core/OrthancException.cpp --- a/Core/OrthancException.cpp Wed Dec 05 12:32:43 2012 +0100 +++ b/Core/OrthancException.cpp Wed Dec 05 12:50:25 2012 +0100 @@ -51,48 +51,51 @@ { switch (error) { - case ErrorCode_Success: - return "Success"; + case ErrorCode_Success: + return "Success"; - case ErrorCode_ParameterOutOfRange: - return "Parameter out of range"; + case ErrorCode_ParameterOutOfRange: + return "Parameter out of range"; - case ErrorCode_NotImplemented: - return "Not implemented yet"; + case ErrorCode_NotImplemented: + return "Not implemented yet"; - case ErrorCode_InternalError: - return "Internal error"; + case ErrorCode_InternalError: + return "Internal error"; - case ErrorCode_NotEnoughMemory: - return "Not enough memory"; + case ErrorCode_NotEnoughMemory: + return "Not enough memory"; - case ErrorCode_UriSyntax: - return "Badly formatted URI"; + case ErrorCode_UriSyntax: + return "Badly formatted URI"; - case ErrorCode_BadParameterType: - return "Bad type for a parameter"; + case ErrorCode_BadParameterType: + return "Bad type for a parameter"; - case ErrorCode_InexistentFile: - return "Inexistent file"; + case ErrorCode_InexistentFile: + return "Inexistent file"; + + case ErrorCode_BadFileFormat: + return "Bad file format"; - case ErrorCode_BadFileFormat: - return "Bad file format"; + case ErrorCode_CannotWriteFile: + return "Cannot write to file"; - case ErrorCode_CannotWriteFile: - return "Cannot write to file"; + case ErrorCode_Timeout: + return "Timeout"; - case ErrorCode_Timeout: - return "Timeout"; + case ErrorCode_UnknownResource: + return "Unknown resource"; - case ErrorCode_UnknownResource: - return "Unknown resource"; + case ErrorCode_BadSequenceOfCalls: + return "Bad sequence of calls"; - case ErrorCode_BadSequenceOfCalls: - return "Bad sequence of calls"; + case ErrorCode_IncompatibleDatabaseVersion: + return "Incompatible version of the database"; - case ErrorCode_Custom: - default: - return "???"; + case ErrorCode_Custom: + default: + return "???"; } } } diff -r 4dc9d00c359c -r bd009f0b1931 NEWS --- a/NEWS Wed Dec 05 12:32:43 2012 +0100 +++ b/NEWS Wed Dec 05 12:50:25 2012 +0100 @@ -2,6 +2,7 @@ =============================== * Download archives of patients, studies and serie as ZIP files +* Orthanc now checks the version of its database schema before starting Version 0.3.0 (2012/11/30) diff -r 4dc9d00c359c -r bd009f0b1931 OrthancServer/DatabaseWrapper.cpp --- a/OrthancServer/DatabaseWrapper.cpp Wed Dec 05 12:32:43 2012 +0100 +++ b/OrthancServer/DatabaseWrapper.cpp Wed Dec 05 12:50:25 2012 +0100 @@ -735,6 +735,27 @@ db_.Execute(query); } + // Sanity check of the version of the database + std::string version = GetGlobalProperty(GlobalProperty_DatabaseSchemaVersion, "Unknown"); + bool ok = false; + try + { + LOG(INFO) << "Version of the Orthanc database: " << version; + unsigned int v = boost::lexical_cast(version); + + // This version of Orthanc is only compatible with version 2 of + // the DB schema (since Orthanc 0.3.1) + ok = (v == 2); + } + catch (boost::bad_lexical_cast&) + { + } + + if (!ok) + { + throw OrthancException(ErrorCode_IncompatibleDatabaseVersion); + } + signalRemainingAncestor_ = new Internals::SignalRemainingAncestor; db_.Register(signalRemainingAncestor_); db_.Register(new Internals::SignalFileDeleted(listener_)); diff -r 4dc9d00c359c -r bd009f0b1931 OrthancServer/PrepareDatabase.sql --- a/OrthancServer/PrepareDatabase.sql Wed Dec 05 12:32:43 2012 +0100 +++ b/OrthancServer/PrepareDatabase.sql Wed Dec 05 12:50:25 2012 +0100 @@ -85,3 +85,7 @@ BEGIN DELETE FROM Resources WHERE internalId = old.parentId; END; + +-- Set the version of the database schema +-- The "1" corresponds to the "GlobalProperty_DatabaseSchemaVersion" enumeration +INSERT INTO GlobalProperties VALUES (1, "2"); diff -r 4dc9d00c359c -r bd009f0b1931 OrthancServer/ServerEnumerations.h --- a/OrthancServer/ServerEnumerations.h Wed Dec 05 12:32:43 2012 +0100 +++ b/OrthancServer/ServerEnumerations.h Wed Dec 05 12:50:25 2012 +0100 @@ -59,7 +59,8 @@ enum GlobalProperty { - GlobalProperty_FlushSleep = 1 + GlobalProperty_DatabaseSchemaVersion = 1, + GlobalProperty_FlushSleep = 2 }; enum ResourceType diff -r 4dc9d00c359c -r bd009f0b1931 UnitTests/ServerIndex.cpp --- a/UnitTests/ServerIndex.cpp Wed Dec 05 12:32:43 2012 +0100 +++ b/UnitTests/ServerIndex.cpp Wed Dec 05 12:50:25 2012 +0100 @@ -180,7 +180,7 @@ index.DeleteResource(a[5]); ASSERT_EQ(0u, index.GetTableRecordCount("Resources")); ASSERT_EQ(0u, index.GetTableRecordCount("AttachedFiles")); - ASSERT_EQ(1u, index.GetTableRecordCount("GlobalProperties")); + ASSERT_EQ(2u, index.GetTableRecordCount("GlobalProperties")); ASSERT_EQ(3u, listener.deletedFiles_.size()); ASSERT_FALSE(listener.deletedFiles_.find("world") == listener.deletedFiles_.end());