Upgrades to utility code for new formats, and a few more database tweaks.
[cumulus.git] / schema.sql
index d225ec1..e0f16a6 100644 (file)
@@ -7,16 +7,21 @@
 create table snapshots (
     snapshotid integer primary key,
     name text not null,
+    scheme text,
     timestamp real
 );
 
 -- List of segments which have been created.
 create table segments (
     segmentid integer primary key,
-    segment text unique not null
+    segment text unique not null,
+    path text,
+    checksum text,
+    mtime real,
+    size integer
 );
 
--- Index of all blocks which have been stored in a snapshot, by checksum.
+-- Index of all blocks which have been stored, by checksum.
 create table block_index (
     blockid integer primary key,
     segmentid integer not null,
@@ -29,10 +34,18 @@ create table block_index (
 create index block_content_index on block_index(checksum);
 create unique index block_name_index on block_index(segmentid, object);
 
--- Index tracking which blocks are used by which snapshots.
-create table snapshot_contents (
-    blockid integer,
-    snapshotid integer
+-- Summary of segment utilization for each snapshots.
+create table segments_used (
+    snapshotid integer not null,
+    segmentid integer not null,
+    utilization real
 );
-create unique index snapshot_contents_unique
-    on snapshot_contents(blockid, snapshotid);
+
+-- 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);