changeset 1176:f24e04838054 db-changes

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 22 Sep 2014 14:11:37 +0200
parents 6fa65ccf312d
children 5b2d8c280ac2
files OrthancServer/PrepareDatabase.sql OrthancServer/Upgrade4To5.sql
diffstat 2 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/PrepareDatabase.sql	Mon Sep 22 13:57:04 2014 +0200
+++ b/OrthancServer/PrepareDatabase.sql	Mon Sep 22 14:11:37 2014 +0200
@@ -18,7 +18,7 @@
        PRIMARY KEY(id, tagGroup, tagElement)
        );
 
--- The following table was added in Orthanc 0.8.4 (database v5)
+-- The following table was added in Orthanc 0.8.5 (database v5)
 CREATE TABLE DicomIdentifiers(
        id INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE,
        tagGroup INTEGER,
@@ -77,11 +77,11 @@
 CREATE INDEX PatientRecyclingIndex ON PatientRecyclingOrder(patientId);
 
 CREATE INDEX MainDicomTagsIndex1 ON MainDicomTags(id);
--- The 2 following indexes were removed in Orthanc 0.8.4 (database v5), to speed up
+-- The 2 following indexes were removed in Orthanc 0.8.5 (database v5), to speed up
 -- CREATE INDEX MainDicomTagsIndex2 ON MainDicomTags(tagGroup, tagElement);
 -- CREATE INDEX MainDicomTagsIndexValues ON MainDicomTags(value COLLATE BINARY);
 
--- The 3 following indexes were added in Orthanc 0.8.4 (database v5)
+-- The 3 following indexes were added in Orthanc 0.8.5 (database v5)
 CREATE INDEX DicomIdentifiersIndex1 ON DicomIdentifiers(id);
 CREATE INDEX DicomIdentifiersIndex2 ON DicomIdentifiers(tagGroup, tagElement);
 CREATE INDEX DicomIdentifiersIndexValues ON DicomIdentifiers(value COLLATE BINARY);
@@ -100,7 +100,7 @@
 CREATE TRIGGER ResourceDeleted
 AFTER DELETE ON Resources
 BEGIN
-  SELECT SignalResourceDeleted(old.publicId, old.resourceType);  -- New in Orthanc 0.8.4 (db v5)
+  SELECT SignalResourceDeleted(old.publicId, old.resourceType);  -- New in Orthanc 0.8.5 (db v5)
   SELECT SignalRemainingAncestor(parent.publicId, parent.resourceType) 
     FROM Resources AS parent WHERE internalId = old.parentId;
 END;
--- a/OrthancServer/Upgrade4To5.sql	Mon Sep 22 13:57:04 2014 +0200
+++ b/OrthancServer/Upgrade4To5.sql	Mon Sep 22 14:11:37 2014 +0200
@@ -42,6 +42,7 @@
 -- Upgrade the "ResourceDeleted" trigger
 
 DROP TRIGGER ResourceDeleted;
+DROP TRIGGER ResourceDeletedParentCleaning;
 
 CREATE TRIGGER ResourceDeleted
 AFTER DELETE ON Resources
@@ -51,6 +52,13 @@
     FROM Resources AS parent WHERE internalId = old.parentId;
 END;
 
+CREATE TRIGGER ResourceDeletedParentCleaning
+AFTER DELETE ON Resources
+FOR EACH ROW WHEN (SELECT COUNT(*) FROM Resources WHERE parentId = old.parentId) = 0
+BEGIN
+  DELETE FROM Resources WHERE internalId = old.parentId;
+END;
+
 
 -- Change the database version
 -- The "1" corresponds to the "GlobalProperty_DatabaseSchemaVersion" enumeration