Slight tweaks to the local database to improve cleaning procedures.
[cumulus.git] / schema.sql
index a0556c5..f406d91 100644 (file)
@@ -8,7 +8,8 @@ create table snapshots (
     snapshotid integer primary key,
     name text not null,
     scheme text,
-    timestamp real
+    timestamp real,
+    intent real
 );
 
 -- List of segments which have been created.
@@ -17,7 +18,9 @@ create table segments (
     segment text unique not null,
     path text,
     checksum text,
-    size integer
+    mtime real,
+    size integer,
+    expire_time integer         -- snapshotid of latest snapshot when expired
 );
 
 -- Index of all blocks which have been stored, by checksum.
@@ -39,3 +42,14 @@ create table segments_used (
     segmentid integer not null,
     utilization real
 );
+create unique index segments_used_index
+    on segments_used(snapshotid, segmentid);
+
+-- Overall estimate of segment utilization, for all snapshots combined.
+create view segment_info as
+select segmentid, mtime, size, cast(size * utilization as integer) as used,
+       utilization
+from segments join
+     (select segmentid, max(utilization) as utilization
+      from segments_used group by segmentid)
+using (segmentid);