diff artifact-database/src/main/resources/sql/org-h2-driver.properties @ 232:202b6ae2fcad

Database cleaner: Removes outdated collections, too. artifacts/trunk@1636 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 31 Mar 2011 17:14:22 +0000
parents 1ea35226a6de
children b35d32e507b6
line wrap: on
line diff
--- a/artifact-database/src/main/resources/sql/org-h2-driver.properties	Thu Mar 31 15:56:50 2011 +0000
+++ b/artifact-database/src/main/resources/sql/org-h2-driver.properties	Thu Mar 31 17:14:22 2011 +0000
@@ -86,6 +86,14 @@
 
 # COLLECTIONS
 
+collections.outdated= \
+    SELECT c.id FROM collections c \
+        INNER JOIN collection_items ci ON c.id = ci.collection_id \
+        INNER JOIN artifacts        a  ON ci.artifact_id = a.id \
+        WHERE c.ttl IS NOT NULL \
+            AND DATEDIFF('MILLISECOND', c.last_access, CURRENT_TIMESTAMP) > c.ttl \
+            AND a.id NOT IN ($LOCKED_IDS$)
+
 collections.touch.trigger.function = \
    UPDATE collections SET last_access = current_timestamp \
    WHERE id IN \
@@ -94,7 +102,6 @@
          INNER JOIN artifacts a         ON a.id = ci.artifact_id \
          WHERE a.id = ?)
 
-
 collections.touch.by.gid =\
     UPDATE collections SET last_access = CURRENT_TIMESTAMP \
         WHERE gid = ?

http://dive4elements.wald.intevation.org